2 * Process management routines for the CUPS scheduler.
4 * Copyright 2007-2015 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
22 #endif /* __APPLE__ */
23 #ifdef HAVE_POSIX_SPAWN
25 extern char **environ
;
26 #endif /* HAVE_POSIX_SPAWN */
27 #ifdef HAVE_POSIX_SPAWN
28 # if !defined(__OpenBSD__) || OpenBSD >= 201505
29 # define USE_POSIX_SPAWN 1
31 # define USE_POSIX_SPAWN 0
32 # endif /* !__OpenBSD__ || */
34 # define USE_POSIX_SPAWN 0
35 #endif /* HAVE_POSIX_SPAWN */
39 * Process structure...
44 int pid
, /* Process ID */
45 job_id
; /* Job associated with process */
46 char name
[1]; /* Name of process */
54 static cups_array_t
*process_array
= NULL
;
61 static int compare_procs(cupsd_proc_t
*a
, cupsd_proc_t
*b
);
63 static char *cupsd_requote(char *dst
, const char *src
, size_t dstsize
);
64 #endif /* HAVE_SANDBOX_H */
68 * 'cupsdCreateProfile()' - Create an execution profile for a subprocess.
71 void * /* O - Profile or NULL on error */
72 cupsdCreateProfile(int job_id
, /* I - Job ID or 0 for none */
73 int allow_networking
)/* I - Allow networking off machine? */
76 cups_file_t
*fp
; /* File pointer */
77 char profile
[1024], /* File containing the profile */
78 bin
[1024], /* Quoted ServerBin */
79 cache
[1024], /* Quoted CacheDir */
80 domain
[1024], /* Domain socket, if any */
81 request
[1024], /* Quoted RequestRoot */
82 root
[1024], /* Quoted ServerRoot */
83 state
[1024], /* Quoted StateDir */
84 temp
[1024]; /* Quoted TempDir */
85 const char *nodebug
; /* " (with no-log)" for no debug */
86 cupsd_listener_t
*lis
; /* Current listening socket */
89 if (!UseSandboxing
|| Sandboxing
== CUPSD_SANDBOXING_OFF
)
92 * Only use sandbox profiles as root...
95 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
100 if ((fp
= cupsTempFile2(profile
, sizeof(profile
))) == NULL
)
102 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
103 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create security profile: %s",
108 fchown(cupsFileNumber(fp
), RunUser
, Group
);
109 fchmod(cupsFileNumber(fp
), 0640);
111 cupsd_requote(bin
, ServerBin
, sizeof(bin
));
112 cupsd_requote(cache
, CacheDir
, sizeof(cache
));
113 cupsd_requote(request
, RequestRoot
, sizeof(request
));
114 cupsd_requote(root
, ServerRoot
, sizeof(root
));
115 cupsd_requote(state
, StateDir
, sizeof(state
));
116 cupsd_requote(temp
, TempDir
, sizeof(temp
));
118 nodebug
= LogLevel
< CUPSD_LOG_DEBUG
? " (with no-log)" : "";
120 cupsFilePuts(fp
, "(version 1)\n");
121 if (Sandboxing
== CUPSD_SANDBOXING_STRICT
)
122 cupsFilePuts(fp
, "(deny default)\n");
124 cupsFilePuts(fp
, "(allow default)\n");
125 if (LogLevel
>= CUPSD_LOG_DEBUG
)
126 cupsFilePuts(fp
, "(debug deny)\n");
127 cupsFilePuts(fp
, "(import \"system.sb\")\n");
128 cupsFilePuts(fp
, "(system-network)\n");
129 cupsFilePuts(fp
, "(allow mach-per-user-lookup)\n");
130 cupsFilePuts(fp
, "(allow ipc-posix-sem)\n");
131 cupsFilePuts(fp
, "(allow ipc-posix-shm)\n");
132 cupsFilePuts(fp
, "(allow ipc-sysv-shm)\n");
133 cupsFilePuts(fp
, "(allow mach-lookup)\n");
136 "(deny file-write* file-read-data file-read-metadata\n"
142 "(deny file-write*\n"
144 " #\"^%s$\"" /* ServerRoot */
145 " #\"^%s/\"" /* ServerRoot/... */
146 " #\"^/private/etc$\""
147 " #\"^/private/etc/\""
148 " #\"^/usr/local/etc$\""
149 " #\"^/usr/local/etc/\""
155 root
, root
, nodebug
);
156 /* Specifically allow applications to stat RequestRoot and some other system folders */
158 "(allow file-read-metadata\n"
161 " #\"^/usr$\"" /* /usr */
162 " #\"^/Library$\"" /* /Library */
163 " #\"^/Library/Printers$\"" /* /Library/Printers */
164 " #\"^%s$\"" /* RequestRoot */
167 /* Read and write TempDir, CacheDir, and other common folders */
169 "(allow file-write* file-read-data file-read-metadata\n"
171 " #\"^/private/var/db/\""
172 " #\"^/private/var/folders/\""
173 " #\"^/private/var/lib/\""
174 " #\"^/private/var/log/\""
175 " #\"^/private/var/mysql/\""
176 " #\"^/private/var/run/\""
177 " #\"^/private/var/spool/\""
178 " #\"^/Library/Application Support/\""
179 " #\"^/Library/Caches/\""
180 " #\"^/Library/Logs/\""
181 " #\"^/Library/Preferences/\""
182 " #\"^/Library/WebServer/\""
183 " #\"^/Users/Shared/\""
186 "(deny file-write*\n"
187 " (regex #\"^%s$\")%s)\n",
190 "(deny file-write* file-read-data file-read-metadata\n"
191 " (regex #\"^%s/\")%s)\n",
194 "(allow file-write* file-read-data file-read-metadata\n"
196 " #\"^%s$\"" /* TempDir */
197 " #\"^%s/\"" /* TempDir/... */
198 " #\"^%s$\"" /* CacheDir */
199 " #\"^%s/\"" /* CacheDir/... */
200 " #\"^%s$\"" /* StateDir */
201 " #\"^%s/\"" /* StateDir/... */
203 temp
, temp
, cache
, cache
, state
, state
);
204 /* Read common folders */
206 "(allow file-read-data file-read-metadata\n"
208 " #\"^/AppleInternal$\""
209 " #\"^/AppleInternal/\""
210 " #\"^/bin$\"" /* /bin */
211 " #\"^/bin/\"" /* /bin/... */
213 " #\"^/private/etc$\""
214 " #\"^/private/etc/\""
215 " #\"^/private/tmp$\""
216 " #\"^/private/tmp/\""
217 " #\"^/private/var$\""
218 " #\"^/private/var/db$\""
219 " #\"^/private/var/folders$\""
220 " #\"^/private/var/lib$\""
221 " #\"^/private/var/log$\""
222 " #\"^/private/var/mysql$\""
223 " #\"^/private/var/run$\""
224 " #\"^/private/var/spool$\""
225 " #\"^/private/var/tmp$\""
226 " #\"^/private/var/tmp/\""
227 " #\"^/usr/bin$\"" /* /usr/bin */
228 " #\"^/usr/bin/\"" /* /usr/bin/... */
229 " #\"^/usr/libexec/cups$\"" /* /usr/libexec/cups */
230 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
231 " #\"^/usr/libexec/fax$\"" /* /usr/libexec/fax */
232 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
233 " #\"^/usr/sbin$\"" /* /usr/sbin */
234 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
235 " #\"^/Library$\"" /* /Library */
236 " #\"^/Library/\"" /* /Library/... */
237 " #\"^/System$\"" /* /System */
238 " #\"^/System/\"" /* /System/... */
239 " #\"^%s/Library$\"" /* RequestRoot/Library */
240 " #\"^%s/Library/\"" /* RequestRoot/Library/... */
241 " #\"^%s$\"" /* ServerBin */
242 " #\"^%s/\"" /* ServerBin/... */
243 " #\"^%s$\"" /* ServerRoot */
244 " #\"^%s/\"" /* ServerRoot/... */
246 request
, request
, bin
, bin
, root
, root
);
247 if (Sandboxing
== CUPSD_SANDBOXING_RELAXED
)
249 /* Limited write access to /Library/Printers/... */
251 "(allow file-write*\n"
253 " #\"^/Library/Printers/.*/\""
256 "(deny file-write*\n"
258 " #\"^/Library/Printers/PPDs$\""
259 " #\"^/Library/Printers/PPDs/\""
260 " #\"^/Library/Printers/PPD Plugins$\""
261 " #\"^/Library/Printers/PPD Plugins/\""
264 /* Allow execution of child processes as long as the programs are not in a user directory */
265 cupsFilePuts(fp
, "(allow process*)\n");
266 cupsFilePuts(fp
, "(deny process-exec (regex #\"^/Users/\"))\n");
267 if (RunUser
&& getenv("CUPS_TESTROOT"))
269 /* Allow source directory access in "make test" environment */
270 char testroot
[1024]; /* Root directory of test files */
272 cupsd_requote(testroot
, getenv("CUPS_TESTROOT"), sizeof(testroot
));
275 "(allow file-write* file-read-data file-read-metadata\n"
277 " #\"^%s$\"" /* CUPS_TESTROOT */
278 " #\"^%s/\"" /* CUPS_TESTROOT/... */
282 "(allow process-exec\n"
284 " #\"^%s/\"" /* CUPS_TESTROOT/... */
287 cupsFilePrintf(fp
, "(allow sysctl*)\n");
291 /* Allow job filters to read the current job files... */
293 "(allow file-read-data file-read-metadata\n"
294 " (regex #\"^%s/([ac]%05d|d%05d-[0-9][0-9][0-9])$\"))\n",
295 request
, job_id
, job_id
);
299 /* Allow email notifications from notifiers... */
301 "(allow process-exec\n"
302 " (literal \"/usr/sbin/sendmail\")\n"
303 " (with no-sandbox))\n");
305 /* Allow access to Bluetooth, USB, and notify_post. */
306 cupsFilePuts(fp
, "(allow iokit*)\n");
307 cupsFilePuts(fp
, "(allow distributed-notification-post)\n");
308 /* Allow outbound networking to local services */
309 cupsFilePuts(fp
, "(allow network-outbound"
310 "\n (regex #\"^/private/var/run/\" #\"^/private/tmp/\" #\"^/private/var/tmp/\")");
311 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
313 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
315 if (httpAddrFamily(&(lis
->address
)) == AF_LOCAL
)
317 httpAddrString(&(lis
->address
), domain
, sizeof(domain
));
318 cupsFilePrintf(fp
, "\n (literal \"%s\")", domain
);
321 if (allow_networking
)
323 /* Allow TCP and UDP networking off the machine... */
324 cupsFilePuts(fp
, "\n (remote tcp))\n");
325 cupsFilePuts(fp
, "(allow network-bind)\n"); /* for LPD resvport */
326 cupsFilePuts(fp
, "(allow network*\n"
327 " (local udp \"*:*\")\n"
328 " (remote udp \"*:*\"))\n");
330 /* Also allow access to device files... */
331 cupsFilePuts(fp
, "(allow file-write* file-read-data file-read-metadata file-ioctl\n"
332 " (regex #\"^/dev/\"))\n");
334 /* And allow kernel extensions to be loaded, e.g., SMB */
335 cupsFilePuts(fp
, "(allow system-kext-load)\n");
339 /* Only allow SNMP (UDP) and LPD (TCP) off the machine... */
340 cupsFilePuts(fp
, ")\n");
341 cupsFilePuts(fp
, "(allow network-outbound\n"
342 " (remote udp \"*:161\")\n"
343 " (remote tcp \"*:515\"))\n");
344 cupsFilePuts(fp
, "(allow network-inbound\n"
345 " (local udp \"localhost:*\"))\n");
349 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d,allow_networking=%d) = \"%s\"", job_id
, allow_networking
, profile
);
350 return ((void *)strdup(profile
));
353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
356 #endif /* HAVE_SANDBOX_H */
361 * 'cupsdDestroyProfile()' - Delete an execution profile.
365 cupsdDestroyProfile(void *profile
) /* I - Profile */
367 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeleteProfile(profile=\"%s\")",
368 profile
? (char *)profile
: "(null)");
370 #ifdef HAVE_SANDBOX_H
373 unlink((char *)profile
);
376 #endif /* HAVE_SANDBOX_H */
381 * 'cupsdEndProcess()' - End a process.
384 int /* O - 0 on success, -1 on failure */
385 cupsdEndProcess(int pid
, /* I - Process ID */
386 int force
) /* I - Force child to die */
388 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdEndProcess(pid=%d, force=%d)", pid
,
397 * When running as root, cupsd puts child processes in their own process
398 * group. Using "-pid" sends a signal to all processes in the group.
405 return (kill(pid
, SIGKILL
));
407 return (kill(pid
, SIGTERM
));
412 * 'cupsdFinishProcess()' - Finish a process and get its name.
415 const char * /* O - Process name */
416 cupsdFinishProcess(int pid
, /* I - Process ID */
417 char *name
, /* I - Name buffer */
418 size_t namelen
, /* I - Size of name buffer */
419 int *job_id
) /* O - Job ID pointer or NULL */
421 cupsd_proc_t key
, /* Search key */
422 *proc
; /* Matching process */
427 if ((proc
= (cupsd_proc_t
*)cupsArrayFind(process_array
, &key
)) != NULL
)
430 *job_id
= proc
->job_id
;
432 strlcpy(name
, proc
->name
, namelen
);
433 cupsArrayRemove(process_array
, proc
);
441 strlcpy(name
, "unknown", namelen
);
444 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFinishProcess(pid=%d, name=%p, namelen=" CUPS_LLFMT
", job_id=%p(%d)) = \"%s\"", pid
, name
, CUPS_LLCAST namelen
, job_id
, job_id
? *job_id
: 0, name
);
451 * 'cupsdStartProcess()' - Start a process.
454 int /* O - Process ID or 0 */
456 const char *command
, /* I - Full path to command */
457 char *argv
[], /* I - Command-line arguments */
458 char *envp
[], /* I - Environment */
459 int infd
, /* I - Standard input file descriptor */
460 int outfd
, /* I - Standard output file descriptor */
461 int errfd
, /* I - Standard error file descriptor */
462 int backfd
, /* I - Backchannel file descriptor */
463 int sidefd
, /* I - Sidechannel file descriptor */
464 int root
, /* I - Run as root? */
465 void *profile
, /* I - Security profile to use */
466 cupsd_job_t
*job
, /* I - Job associated with process */
467 int *pid
) /* O - Process ID */
469 int i
; /* Looping var */
470 const char *exec_path
= command
; /* Command to be exec'd */
471 char *real_argv
[110], /* Real command-line arguments */
472 cups_exec
[1024], /* Path to "cups-exec" program */
473 user_str
[16], /* User string */
474 group_str
[16], /* Group string */
475 nice_str
[16]; /* FilterNice string */
476 uid_t user
; /* Command UID */
477 cupsd_proc_t
*proc
; /* New process record */
479 posix_spawn_file_actions_t actions
; /* Spawn file actions */
480 posix_spawnattr_t attrs
; /* Spawn attributes */
481 sigset_t defsignals
; /* Default signals */
482 #elif defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
483 struct sigaction action
; /* POSIX signal handler */
484 #endif /* USE_POSIX_SPAWN */
485 #if defined(__APPLE__)
486 char processPath
[1024], /* CFProcessPath environment variable */
487 linkpath
[1024]; /* Link path for symlinks... */
488 int linkbytes
; /* Bytes for link path */
489 #endif /* __APPLE__ */
495 * Figure out the UID for the child process...
506 * Check the permissions of the command we are running...
509 if (_cupsFileCheck(command
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
510 cupsdLogFCMessage
, job
? job
->printer
: NULL
))
513 #if defined(__APPLE__)
517 * Add special voodoo magic for macOS - this allows macOS programs to access
518 * their bundle resources properly...
521 if ((linkbytes
= readlink(command
, linkpath
, sizeof(linkpath
) - 1)) > 0)
524 * Yes, this is a symlink to the actual program, nul-terminate and
528 linkpath
[linkbytes
] = '\0';
530 if (linkpath
[0] == '/')
531 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s",
534 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s/%s",
535 dirname((char *)command
), linkpath
);
538 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s", command
);
540 envp
[0] = processPath
; /* Replace <CFProcessPath> string */
542 #endif /* __APPLE__ */
545 * Use helper program when we have a sandbox profile...
550 #endif /* !USE_POSIX_SPAWN */
552 snprintf(cups_exec
, sizeof(cups_exec
), "%s/daemon/cups-exec", ServerBin
);
553 snprintf(user_str
, sizeof(user_str
), "%d", user
);
554 snprintf(group_str
, sizeof(group_str
), "%d", Group
);
555 snprintf(nice_str
, sizeof(nice_str
), "%d", FilterNice
);
557 real_argv
[0] = cups_exec
;
558 real_argv
[1] = (char *)"-g";
559 real_argv
[2] = group_str
;
560 real_argv
[3] = (char *)"-n";
561 real_argv
[4] = nice_str
;
562 real_argv
[5] = (char *)"-u";
563 real_argv
[6] = user_str
;
564 real_argv
[7] = profile
? profile
: "none";
565 real_argv
[8] = (char *)command
;
568 i
< (int)(sizeof(real_argv
) / sizeof(real_argv
[0]) - 10) && argv
[i
];
570 real_argv
[i
+ 9] = argv
[i
];
572 real_argv
[i
+ 9] = NULL
;
575 exec_path
= cups_exec
;
578 if (LogLevel
== CUPSD_LOG_DEBUG2
)
580 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Preparing to start \"%s\", arguments:", command
);
582 for (i
= 0; argv
[i
]; i
++)
583 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: argv[%d] = \"%s\"", i
, argv
[i
]);
588 * Setup attributes and file actions for the spawn...
591 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting spawn attributes.");
592 sigemptyset(&defsignals
);
593 sigaddset(&defsignals
, SIGTERM
);
594 sigaddset(&defsignals
, SIGCHLD
);
595 sigaddset(&defsignals
, SIGPIPE
);
597 posix_spawnattr_init(&attrs
);
598 posix_spawnattr_setflags(&attrs
, POSIX_SPAWN_SETPGROUP
| POSIX_SPAWN_SETSIGDEF
);
599 posix_spawnattr_setpgroup(&attrs
, 0);
600 posix_spawnattr_setsigdefault(&attrs
, &defsignals
);
602 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting file actions.");
603 posix_spawn_file_actions_init(&actions
);
607 posix_spawn_file_actions_addopen(&actions
, 0, "/dev/null", O_RDONLY
, 0);
609 posix_spawn_file_actions_adddup2(&actions
, infd
, 0);
615 posix_spawn_file_actions_addopen(&actions
, 1, "/dev/null", O_WRONLY
, 0);
617 posix_spawn_file_actions_adddup2(&actions
, outfd
, 1);
623 posix_spawn_file_actions_addopen(&actions
, 2, "/dev/null", O_WRONLY
, 0);
625 posix_spawn_file_actions_adddup2(&actions
, errfd
, 2);
628 if (backfd
!= 3 && backfd
>= 0)
629 posix_spawn_file_actions_adddup2(&actions
, backfd
, 3);
631 if (sidefd
!= 4 && sidefd
>= 0)
632 posix_spawn_file_actions_adddup2(&actions
, sidefd
, 4);
634 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Calling posix_spawn.");
636 if (posix_spawn(pid
, exec_path
, &actions
, &attrs
, argv
, envp
? envp
: environ
))
638 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
, strerror(errno
));
643 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: pid=%d", (int)*pid
);
645 posix_spawn_file_actions_destroy(&actions
);
646 posix_spawnattr_destroy(&attrs
);
650 * Block signals before forking...
655 if ((*pid
= fork()) == 0)
658 * Child process goes here; update stderr as needed...
664 errfd
= open("/dev/null", O_WRONLY
);
674 * Put this process in its own process group so that we can kill any child
675 * processes it creates.
679 if (!RunUser
&& setpgid(0, 0))
682 if (!RunUser
&& setpgrp())
684 # endif /* HAVE_SETPGID */
687 * Update the remaining file descriptors as needed...
693 infd
= open("/dev/null", O_RDONLY
);
705 outfd
= open("/dev/null", O_WRONLY
);
714 if (backfd
!= 3 && backfd
>= 0)
718 fcntl(3, F_SETFL
, O_NDELAY
);
721 if (sidefd
!= 4 && sidefd
>= 0)
725 fcntl(4, F_SETFL
, O_NDELAY
);
729 * Change the priority of the process based on the FilterNice setting.
730 * (this is not done for root processes...)
737 * Reset group membership to just the main one we belong to.
740 if (!RunUser
&& setgid(Group
))
743 if (!RunUser
&& setgroups(1, &Group
))
747 * Change user to something "safe"...
750 if (!RunUser
&& user
&& setuid(user
))
754 * Change umask to restrict permissions on created files...
760 * Unblock signals before doing the exec...
764 sigset(SIGTERM
, SIG_DFL
);
765 sigset(SIGCHLD
, SIG_DFL
);
766 sigset(SIGPIPE
, SIG_DFL
);
767 # elif defined(HAVE_SIGACTION)
768 memset(&action
, 0, sizeof(action
));
770 sigemptyset(&action
.sa_mask
);
771 action
.sa_handler
= SIG_DFL
;
773 sigaction(SIGTERM
, &action
, NULL
);
774 sigaction(SIGCHLD
, &action
, NULL
);
775 sigaction(SIGPIPE
, &action
, NULL
);
777 signal(SIGTERM
, SIG_DFL
);
778 signal(SIGCHLD
, SIG_DFL
);
779 signal(SIGPIPE
, SIG_DFL
);
780 # endif /* HAVE_SIGSET */
782 cupsdReleaseSignals();
785 * Execute the command; if for some reason this doesn't work, log an error
786 * exit with a non-zero value...
790 execve(exec_path
, argv
, envp
);
792 execv(exec_path
, argv
);
799 * Error - couldn't fork a new process!
802 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
,
808 cupsdReleaseSignals();
809 #endif /* USE_POSIX_SPAWN */
814 process_array
= cupsArrayNew((cups_array_func_t
)compare_procs
, NULL
);
818 if ((proc
= calloc(1, sizeof(cupsd_proc_t
) + strlen(command
))) != NULL
)
821 proc
->job_id
= job
? job
->id
: 0;
822 _cups_strcpy(proc
->name
, command
);
824 cupsArrayAdd(process_array
, proc
);
829 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
830 "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
831 "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
832 "profile=%p, job=%p(%d), pid=%p) = %d",
833 command
, argv
, envp
, infd
, outfd
, errfd
, backfd
, sidefd
,
834 root
, profile
, job
, job
? job
->id
: 0, pid
, *pid
);
841 * 'compare_procs()' - Compare two processes.
844 static int /* O - Result of comparison */
845 compare_procs(cupsd_proc_t
*a
, /* I - First process */
846 cupsd_proc_t
*b
) /* I - Second process */
848 return (a
->pid
- b
->pid
);
852 #ifdef HAVE_SANDBOX_H
854 * 'cupsd_requote()' - Make a regular-expression version of a string.
857 static char * /* O - Quoted string */
858 cupsd_requote(char *dst
, /* I - Destination buffer */
859 const char *src
, /* I - Source string */
860 size_t dstsize
) /* I - Size of destination buffer */
862 int ch
; /* Current character */
863 char *dstptr
, /* Current position in buffer */
864 *dstend
; /* End of destination buffer */
868 dstend
= dst
+ dstsize
- 2;
870 while (*src
&& dstptr
< dstend
)
874 if (ch
== '/' && !*src
)
875 break; /* Don't add trailing slash */
877 if (strchr(".?*()[]^$\\", ch
))
880 *dstptr
++ = (char)ch
;
887 #endif /* HAVE_SANDBOX_H */