@@ -591,6 +591,139 @@ cdef class NotificationResponse:
591591 """
592592 self ._flags = value
593593
594+ cdef class NotificationAddfd:
595+ """ Python object representing a seccomp notification addfd structure.
596+ """
597+ cdef uint64_t _id
598+ cdef uint32_t _flags
599+ cdef uint32_t _srcfd
600+ cdef uint32_t _newfd
601+ cdef uint32_t _newfd_flags
602+
603+ def __cinit__ (self , notify , flags , srcfd , newfd = 0 , newflags = 0 ):
604+ """ Initialize the notification addfd structure.
605+
606+ Arguments:
607+ notify - a Notification object
608+ srcfd - the source file descriptor
609+ flags - notify addfd flags
610+ newfd - 0 or desired file descriptor number in target
611+ newflags - new flags to set on the target file descriptor
612+
613+ Description:
614+ Create a seccomp NotificationAddfd object.
615+ """
616+ self ._id = notify.id
617+ self ._flags = flags
618+ self ._srcfd = srcfd
619+ self ._newfd = newfd
620+ self ._newfd_flags = newflags
621+
622+ @property
623+ def id (self ):
624+ """ Get the seccomp notification request ID.
625+
626+ Description:
627+ Get the seccomp notification request ID.
628+ """
629+ return self ._id
630+
631+ @id .setter
632+ def id (self , value ):
633+ """ Set the seccomp notification request ID.
634+
635+ Arguments:
636+ id - the seccomp notification request ID
637+
638+ Description:
639+ Set the seccomp notification request ID.
640+ """
641+ self ._id = value
642+
643+ @property
644+ def flags (self ):
645+ """ Get the seccomp notification addfd flags.
646+
647+ Description:
648+ Get the seccomp notification addfd flags.
649+ """
650+ return self ._flags
651+
652+ @flags.setter
653+ def flags (self , value ):
654+ """ Set the seccomp notification addfd flags.
655+
656+ Arguments:
657+ flags - the notification addfd flags
658+
659+ Description:
660+ Set the seccomp notification addfd flags.
661+ """
662+ self ._flags = value
663+
664+ @property
665+ def srcfd (self ):
666+ """ Get the local file descriptor number.
667+
668+ Description:
669+ Get the local file descriptor number.
670+ """
671+ return self ._srcfd
672+
673+ @srcfd.setter
674+ def srcfd (self , value ):
675+ """ Set the local file descriptor number.
676+
677+ Arguments:
678+ srcfd - the local file descriptor number
679+
680+ Description:
681+ Set the local file descriptor number.
682+ """
683+ self ._srcfd = value
684+
685+ @property
686+ def newfd (self ):
687+ """ Get the target file descriptor number.
688+
689+ Description:
690+ Get the target file descriptor number.
691+ """
692+ return self ._newfd
693+
694+ @newfd.setter
695+ def newfd (self , value ):
696+ """ Set the target file descriptor number.
697+
698+ Arguments:
699+ newfd - the target file descriptor number
700+
701+ Description:
702+ Set the target file descriptor number.
703+ """
704+ self ._newfd = value
705+
706+ @property
707+ def newflags (self ):
708+ """ Get the new flags to set on the target file descriptor.
709+
710+ Description:
711+ Get the new flags to set on the target file descriptor.
712+ """
713+ return self ._newfd_flags
714+
715+ @newflags.setter
716+ def newflags (self , value ):
717+ """ Set the new flags to set on the target file descriptor.
718+
719+ Arguments:
720+ newflags - the new flags to set on the target file descriptor
721+
722+ Description:
723+ Set the new flags to set on the target file descriptor.
724+ """
725+ self ._newfd_flags = value
726+
594727cdef class SyscallFilter:
595728 """ Python object representing a seccomp syscall filter. """
596729 cdef int _defaction
@@ -959,16 +1092,20 @@ cdef class SyscallFilter:
9591092 if rc != 0 :
9601093 raise RuntimeError (str .format(" Library error (errno = {0})" , rc))
9611094
962- def receive_notify (self ):
1095+ def receive_notify (self , fd = None ):
9631096 """ Receive seccomp notifications.
9641097
1098+ Arguments:
1099+ fd - the notify file descriptor
1100+
9651101 Description:
9661102 Receive a seccomp notification from the system, requires the use of
9671103 the NOTIFY action.
9681104 """
9691105 cdef libseccomp.seccomp_notif * req
9701106
971- fd = libseccomp.seccomp_notify_fd(self ._ctx)
1107+ if fd is None :
1108+ fd = libseccomp.seccomp_notify_fd(self ._ctx)
9721109 if fd < 0 :
9731110 raise RuntimeError (" Notifications not enabled/active" )
9741111 rc = libseccomp.seccomp_notify_alloc(& req, NULL )
@@ -988,18 +1125,20 @@ cdef class SyscallFilter:
9881125 free(req)
9891126 return notify
9901127
991- def respond_notify (self , response ):
1128+ def respond_notify (self , response , fd = None ):
9921129 """ Send a seccomp notification response.
9931130
9941131 Arguments:
9951132 response - the response to send to the system
1133+ fd - the notify file descriptor
9961134
9971135 Description:
9981136 Respond to a seccomp notification.
9991137 """
10001138 cdef libseccomp.seccomp_notif_resp * resp
10011139
1002- fd = libseccomp.seccomp_notify_fd(self ._ctx)
1140+ if fd is None :
1141+ fd = libseccomp.seccomp_notify_fd(self ._ctx)
10031142 if fd < 0 :
10041143 raise RuntimeError (" Notifications not enabled/active" )
10051144 rc = libseccomp.seccomp_notify_alloc(NULL , & resp)
@@ -1026,6 +1165,34 @@ cdef class SyscallFilter:
10261165 raise RuntimeError (" Notifications not enabled/active" )
10271166 return fd
10281167
1168+ def notify_addfd (self , addfd_obj , fd = None ):
1169+ """ Add a file descriptor to supervisee
1170+
1171+ Arguments:
1172+ addfd_obj - the addfd object
1173+ fd - the notify file descriptor
1174+
1175+ Description:
1176+ Add a file descriptor to the supervisee process.
1177+ """
1178+ if fd is None :
1179+ fd = libseccomp.seccomp_notify_fd(self ._ctx)
1180+ if fd < 0 :
1181+ raise RuntimeError (" Notifications not enabled/active" )
1182+
1183+ cdef libseccomp.seccomp_notif_addfd addfd
1184+
1185+ addfd.id = addfd_obj.id
1186+ addfd.flags = addfd_obj.flags
1187+ addfd.srcfd = addfd_obj.srcfd
1188+ addfd.newfd = addfd_obj.newfd
1189+ addfd.newfd_flags = addfd_obj.newflags
1190+
1191+ rc = libseccomp.seccomp_notify_addfd(fd, & addfd)
1192+ if rc < 0 :
1193+ raise RuntimeError (str .format(" Library error (errno = {0})" , rc))
1194+ return rc
1195+
10291196 def export_pfc (self , file ):
10301197 """ Export the filter in PFC format.
10311198
0 commit comments