2 * "$Id: process.c 13138 2016-03-15 14:59:54Z msweet $"
4 * Process management routines for the CUPS scheduler.
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * Include necessary headers...
24 #endif /* __APPLE__ */
25 #ifdef HAVE_POSIX_SPAWN
27 extern char **environ
;
28 #endif /* HAVE_POSIX_SPAWN */
29 #ifdef HAVE_POSIX_SPAWN
30 # if !defined(__OpenBSD__) || OpenBSD >= 201505
31 # define USE_POSIX_SPAWN 1
33 # define USE_POSIX_SPAWN 0
34 # endif /* !__OpenBSD__ || */
36 # define USE_POSIX_SPAWN 0
37 #endif /* HAVE_POSIX_SPAWN */
41 * Process structure...
46 int pid
, /* Process ID */
47 job_id
; /* Job associated with process */
48 char name
[1]; /* Name of process */
56 static cups_array_t
*process_array
= NULL
;
63 static int compare_procs(cupsd_proc_t
*a
, cupsd_proc_t
*b
);
65 static char *cupsd_requote(char *dst
, const char *src
, size_t dstsize
);
66 #endif /* HAVE_SANDBOX_H */
70 * 'cupsdCreateProfile()' - Create an execution profile for a subprocess.
73 void * /* O - Profile or NULL on error */
74 cupsdCreateProfile(int job_id
, /* I - Job ID or 0 for none */
75 int allow_networking
)/* I - Allow networking off machine? */
78 cups_file_t
*fp
; /* File pointer */
79 char profile
[1024], /* File containing the profile */
80 bin
[1024], /* Quoted ServerBin */
81 cache
[1024], /* Quoted CacheDir */
82 domain
[1024], /* Domain socket, if any */
83 request
[1024], /* Quoted RequestRoot */
84 root
[1024], /* Quoted ServerRoot */
85 state
[1024], /* Quoted StateDir */
86 temp
[1024]; /* Quoted TempDir */
87 const char *nodebug
; /* " (with no-log)" for no debug */
88 cupsd_listener_t
*lis
; /* Current listening socket */
91 if (!UseSandboxing
|| Sandboxing
== CUPSD_SANDBOXING_OFF
)
94 * Only use sandbox profiles as root...
97 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
102 if ((fp
= cupsTempFile2(profile
, sizeof(profile
))) == NULL
)
104 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
105 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create security profile: %s",
110 fchown(cupsFileNumber(fp
), RunUser
, Group
);
111 fchmod(cupsFileNumber(fp
), 0640);
113 cupsd_requote(bin
, ServerBin
, sizeof(bin
));
114 cupsd_requote(cache
, CacheDir
, sizeof(cache
));
115 cupsd_requote(request
, RequestRoot
, sizeof(request
));
116 cupsd_requote(root
, ServerRoot
, sizeof(root
));
117 cupsd_requote(state
, StateDir
, sizeof(state
));
118 cupsd_requote(temp
, TempDir
, sizeof(temp
));
120 nodebug
= LogLevel
< CUPSD_LOG_DEBUG
? " (with no-log)" : "";
122 cupsFilePuts(fp
, "(version 1)\n");
123 if (Sandboxing
== CUPSD_SANDBOXING_STRICT
)
124 cupsFilePuts(fp
, "(deny default)\n");
126 cupsFilePuts(fp
, "(allow default)\n");
127 if (LogLevel
>= CUPSD_LOG_DEBUG
)
128 cupsFilePuts(fp
, "(debug deny)\n");
129 cupsFilePuts(fp
, "(import \"system.sb\")\n");
130 cupsFilePuts(fp
, "(system-network)\n");
131 cupsFilePuts(fp
, "(allow mach-per-user-lookup)\n");
132 cupsFilePuts(fp
, "(allow ipc-posix-sem)\n");
133 cupsFilePuts(fp
, "(allow ipc-posix-shm)\n");
134 cupsFilePuts(fp
, "(allow ipc-sysv-shm)\n");
135 cupsFilePuts(fp
, "(allow mach-lookup)\n");
138 "(deny file-write* file-read-data file-read-metadata\n"
144 "(deny file-write*\n"
146 " #\"^%s$\"" /* ServerRoot */
147 " #\"^%s/\"" /* ServerRoot/... */
148 " #\"^/private/etc$\""
149 " #\"^/private/etc/\""
150 " #\"^/usr/local/etc$\""
151 " #\"^/usr/local/etc/\""
157 root
, root
, nodebug
);
158 /* Specifically allow applications to stat RequestRoot and some other system folders */
160 "(allow file-read-metadata\n"
163 " #\"^/usr$\"" /* /usr */
164 " #\"^/Library$\"" /* /Library */
165 " #\"^/Library/Printers$\"" /* /Library/Printers */
166 " #\"^%s$\"" /* RequestRoot */
169 /* Read and write TempDir, CacheDir, and other common folders */
171 "(allow file-write* file-read-data file-read-metadata\n"
173 " #\"^/private/var/db/\""
174 " #\"^/private/var/folders/\""
175 " #\"^/private/var/lib/\""
176 " #\"^/private/var/log/\""
177 " #\"^/private/var/mysql/\""
178 " #\"^/private/var/run/\""
179 " #\"^/private/var/spool/\""
180 " #\"^/Library/Application Support/\""
181 " #\"^/Library/Caches/\""
182 " #\"^/Library/Logs/\""
183 " #\"^/Library/Preferences/\""
184 " #\"^/Library/WebServer/\""
185 " #\"^/Users/Shared/\""
188 "(deny file-write*\n"
189 " (regex #\"^%s$\")%s)\n",
192 "(deny file-write* file-read-data file-read-metadata\n"
193 " (regex #\"^%s/\")%s)\n",
196 "(allow file-write* file-read-data file-read-metadata\n"
198 " #\"^%s$\"" /* TempDir */
199 " #\"^%s/\"" /* TempDir/... */
200 " #\"^%s$\"" /* CacheDir */
201 " #\"^%s/\"" /* CacheDir/... */
202 " #\"^%s$\"" /* StateDir */
203 " #\"^%s/\"" /* StateDir/... */
205 temp
, temp
, cache
, cache
, state
, state
);
206 /* Read common folders */
208 "(allow file-read-data file-read-metadata\n"
210 " #\"^/AppleInternal$\""
211 " #\"^/AppleInternal/\""
212 " #\"^/bin$\"" /* /bin */
213 " #\"^/bin/\"" /* /bin/... */
215 " #\"^/private/etc$\""
216 " #\"^/private/etc/\""
217 " #\"^/private/tmp$\""
218 " #\"^/private/tmp/\""
219 " #\"^/private/var$\""
220 " #\"^/private/var/db$\""
221 " #\"^/private/var/folders$\""
222 " #\"^/private/var/lib$\""
223 " #\"^/private/var/log$\""
224 " #\"^/private/var/mysql$\""
225 " #\"^/private/var/run$\""
226 " #\"^/private/var/spool$\""
227 " #\"^/private/var/tmp$\""
228 " #\"^/private/var/tmp/\""
229 " #\"^/usr/bin$\"" /* /usr/bin */
230 " #\"^/usr/bin/\"" /* /usr/bin/... */
231 " #\"^/usr/libexec/cups$\"" /* /usr/libexec/cups */
232 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
233 " #\"^/usr/libexec/fax$\"" /* /usr/libexec/fax */
234 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
235 " #\"^/usr/sbin$\"" /* /usr/sbin */
236 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
237 " #\"^/Library$\"" /* /Library */
238 " #\"^/Library/\"" /* /Library/... */
239 " #\"^/System$\"" /* /System */
240 " #\"^/System/\"" /* /System/... */
241 " #\"^%s/Library$\"" /* RequestRoot/Library */
242 " #\"^%s/Library/\"" /* RequestRoot/Library/... */
243 " #\"^%s$\"" /* ServerBin */
244 " #\"^%s/\"" /* ServerBin/... */
245 " #\"^%s$\"" /* ServerRoot */
246 " #\"^%s/\"" /* ServerRoot/... */
248 request
, request
, bin
, bin
, root
, root
);
249 if (Sandboxing
== CUPSD_SANDBOXING_RELAXED
)
251 /* Limited write access to /Library/Printers/... */
253 "(allow file-write*\n"
255 " #\"^/Library/Printers/.*/\""
258 "(deny file-write*\n"
260 " #\"^/Library/Printers/PPDs$\""
261 " #\"^/Library/Printers/PPDs/\""
262 " #\"^/Library/Printers/PPD Plugins$\""
263 " #\"^/Library/Printers/PPD Plugins/\""
266 /* Allow execution of child processes as long as the programs are not in a user directory */
267 cupsFilePuts(fp
, "(allow process*)\n");
268 cupsFilePuts(fp
, "(deny process-exec (regex #\"^/Users/\"))\n");
269 if (RunUser
&& getenv("CUPS_TESTROOT"))
271 /* Allow source directory access in "make test" environment */
272 char testroot
[1024]; /* Root directory of test files */
274 cupsd_requote(testroot
, getenv("CUPS_TESTROOT"), sizeof(testroot
));
277 "(allow file-write* file-read-data file-read-metadata\n"
279 " #\"^%s$\"" /* CUPS_TESTROOT */
280 " #\"^%s/\"" /* CUPS_TESTROOT/... */
284 "(allow process-exec\n"
286 " #\"^%s/\"" /* CUPS_TESTROOT/... */
289 cupsFilePrintf(fp
, "(allow sysctl*)\n");
293 /* Allow job filters to read the current job files... */
295 "(allow file-read-data file-read-metadata\n"
296 " (regex #\"^%s/([ac]%05d|d%05d-[0-9][0-9][0-9])$\"))\n",
297 request
, job_id
, job_id
);
301 /* Allow email notifications from notifiers... */
303 "(allow process-exec\n"
304 " (literal \"/usr/sbin/sendmail\")\n"
305 " (with no-sandbox))\n");
307 /* Allow access to Bluetooth, USB, and notify_post. */
308 cupsFilePuts(fp
, "(allow iokit*)\n");
309 cupsFilePuts(fp
, "(allow distributed-notification-post)\n");
310 /* Allow outbound networking to local services */
311 cupsFilePuts(fp
, "(allow network-outbound"
312 "\n (regex #\"^/private/var/run/\" #\"^/private/tmp/\" #\"^/private/var/tmp/\")");
313 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
315 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
317 if (httpAddrFamily(&(lis
->address
)) == AF_LOCAL
)
319 httpAddrString(&(lis
->address
), domain
, sizeof(domain
));
320 cupsFilePrintf(fp
, "\n (literal \"%s\")", domain
);
323 if (allow_networking
)
325 /* Allow TCP and UDP networking off the machine... */
326 cupsFilePuts(fp
, "\n (remote tcp))\n");
327 cupsFilePuts(fp
, "(allow network-bind)\n"); /* for LPD resvport */
328 cupsFilePuts(fp
, "(allow network*\n"
329 " (local udp \"*:*\")\n"
330 " (remote udp \"*:*\"))\n");
332 /* Also allow access to device files... */
333 cupsFilePuts(fp
, "(allow file-write* file-read-data file-read-metadata file-ioctl\n"
334 " (regex #\"^/dev/\"))\n");
336 /* And allow kernel extensions to be loaded, e.g., SMB */
337 cupsFilePuts(fp
, "(allow system-kext-load)\n");
341 /* Only allow SNMP (UDP) and LPD (TCP) off the machine... */
342 cupsFilePuts(fp
, ")\n");
343 cupsFilePuts(fp
, "(allow network-outbound\n"
344 " (remote udp \"*:161\")\n"
345 " (remote tcp \"*:515\"))\n");
346 cupsFilePuts(fp
, "(allow network-inbound\n"
347 " (local udp \"localhost:*\"))\n");
351 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d,allow_networking=%d) = \"%s\"", job_id
, allow_networking
, profile
);
352 return ((void *)strdup(profile
));
355 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
358 #endif /* HAVE_SANDBOX_H */
363 * 'cupsdDestroyProfile()' - Delete an execution profile.
367 cupsdDestroyProfile(void *profile
) /* I - Profile */
369 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeleteProfile(profile=\"%s\")",
370 profile
? (char *)profile
: "(null)");
372 #ifdef HAVE_SANDBOX_H
375 unlink((char *)profile
);
378 #endif /* HAVE_SANDBOX_H */
383 * 'cupsdEndProcess()' - End a process.
386 int /* O - 0 on success, -1 on failure */
387 cupsdEndProcess(int pid
, /* I - Process ID */
388 int force
) /* I - Force child to die */
390 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdEndProcess(pid=%d, force=%d)", pid
,
399 * When running as root, cupsd puts child processes in their own process
400 * group. Using "-pid" sends a signal to all processes in the group.
407 return (kill(pid
, SIGKILL
));
409 return (kill(pid
, SIGTERM
));
414 * 'cupsdFinishProcess()' - Finish a process and get its name.
417 const char * /* O - Process name */
418 cupsdFinishProcess(int pid
, /* I - Process ID */
419 char *name
, /* I - Name buffer */
420 size_t namelen
, /* I - Size of name buffer */
421 int *job_id
) /* O - Job ID pointer or NULL */
423 cupsd_proc_t key
, /* Search key */
424 *proc
; /* Matching process */
429 if ((proc
= (cupsd_proc_t
*)cupsArrayFind(process_array
, &key
)) != NULL
)
432 *job_id
= proc
->job_id
;
434 strlcpy(name
, proc
->name
, namelen
);
435 cupsArrayRemove(process_array
, proc
);
443 strlcpy(name
, "unknown", namelen
);
446 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
);
453 * 'cupsdStartProcess()' - Start a process.
456 int /* O - Process ID or 0 */
458 const char *command
, /* I - Full path to command */
459 char *argv
[], /* I - Command-line arguments */
460 char *envp
[], /* I - Environment */
461 int infd
, /* I - Standard input file descriptor */
462 int outfd
, /* I - Standard output file descriptor */
463 int errfd
, /* I - Standard error file descriptor */
464 int backfd
, /* I - Backchannel file descriptor */
465 int sidefd
, /* I - Sidechannel file descriptor */
466 int root
, /* I - Run as root? */
467 void *profile
, /* I - Security profile to use */
468 cupsd_job_t
*job
, /* I - Job associated with process */
469 int *pid
) /* O - Process ID */
471 int i
; /* Looping var */
472 const char *exec_path
= command
; /* Command to be exec'd */
473 char *real_argv
[110], /* Real command-line arguments */
474 cups_exec
[1024], /* Path to "cups-exec" program */
475 user_str
[16], /* User string */
476 group_str
[16], /* Group string */
477 nice_str
[16]; /* FilterNice string */
478 uid_t user
; /* Command UID */
479 cupsd_proc_t
*proc
; /* New process record */
481 posix_spawn_file_actions_t actions
; /* Spawn file actions */
482 posix_spawnattr_t attrs
; /* Spawn attributes */
483 sigset_t defsignals
; /* Default signals */
484 #elif defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
485 struct sigaction action
; /* POSIX signal handler */
486 #endif /* USE_POSIX_SPAWN */
487 #if defined(__APPLE__)
488 char processPath
[1024], /* CFProcessPath environment variable */
489 linkpath
[1024]; /* Link path for symlinks... */
490 int linkbytes
; /* Bytes for link path */
491 #endif /* __APPLE__ */
497 * Figure out the UID for the child process...
508 * Check the permissions of the command we are running...
511 if (_cupsFileCheck(command
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
512 cupsdLogFCMessage
, job
? job
->printer
: NULL
))
515 #if defined(__APPLE__)
519 * Add special voodoo magic for OS X - this allows OS X programs to access
520 * their bundle resources properly...
523 if ((linkbytes
= readlink(command
, linkpath
, sizeof(linkpath
) - 1)) > 0)
526 * Yes, this is a symlink to the actual program, nul-terminate and
530 linkpath
[linkbytes
] = '\0';
532 if (linkpath
[0] == '/')
533 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s",
536 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s/%s",
537 dirname((char *)command
), linkpath
);
540 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s", command
);
542 envp
[0] = processPath
; /* Replace <CFProcessPath> string */
544 #endif /* __APPLE__ */
547 * Use helper program when we have a sandbox profile...
552 #endif /* !USE_POSIX_SPAWN */
554 snprintf(cups_exec
, sizeof(cups_exec
), "%s/daemon/cups-exec", ServerBin
);
555 snprintf(user_str
, sizeof(user_str
), "%d", user
);
556 snprintf(group_str
, sizeof(group_str
), "%d", Group
);
557 snprintf(nice_str
, sizeof(nice_str
), "%d", FilterNice
);
559 real_argv
[0] = cups_exec
;
560 real_argv
[1] = (char *)"-g";
561 real_argv
[2] = group_str
;
562 real_argv
[3] = (char *)"-n";
563 real_argv
[4] = nice_str
;
564 real_argv
[5] = (char *)"-u";
565 real_argv
[6] = user_str
;
566 real_argv
[7] = profile
? profile
: "none";
567 real_argv
[8] = (char *)command
;
570 i
< (int)(sizeof(real_argv
) / sizeof(real_argv
[0]) - 10) && argv
[i
];
572 real_argv
[i
+ 9] = argv
[i
];
574 real_argv
[i
+ 9] = NULL
;
577 exec_path
= cups_exec
;
580 if (LogLevel
== CUPSD_LOG_DEBUG2
)
582 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Preparing to start \"%s\", arguments:", command
);
584 for (i
= 0; argv
[i
]; i
++)
585 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: argv[%d] = \"%s\"", i
, argv
[i
]);
590 * Setup attributes and file actions for the spawn...
593 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting spawn attributes.");
594 sigemptyset(&defsignals
);
595 sigaddset(&defsignals
, SIGTERM
);
596 sigaddset(&defsignals
, SIGCHLD
);
597 sigaddset(&defsignals
, SIGPIPE
);
599 posix_spawnattr_init(&attrs
);
600 posix_spawnattr_setflags(&attrs
, POSIX_SPAWN_SETPGROUP
| POSIX_SPAWN_SETSIGDEF
);
601 posix_spawnattr_setpgroup(&attrs
, 0);
602 posix_spawnattr_setsigdefault(&attrs
, &defsignals
);
604 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting file actions.");
605 posix_spawn_file_actions_init(&actions
);
609 posix_spawn_file_actions_addopen(&actions
, 0, "/dev/null", O_RDONLY
, 0);
611 posix_spawn_file_actions_adddup2(&actions
, infd
, 0);
617 posix_spawn_file_actions_addopen(&actions
, 1, "/dev/null", O_WRONLY
, 0);
619 posix_spawn_file_actions_adddup2(&actions
, outfd
, 1);
625 posix_spawn_file_actions_addopen(&actions
, 2, "/dev/null", O_WRONLY
, 0);
627 posix_spawn_file_actions_adddup2(&actions
, errfd
, 2);
630 if (backfd
!= 3 && backfd
>= 0)
631 posix_spawn_file_actions_adddup2(&actions
, backfd
, 3);
633 if (sidefd
!= 4 && sidefd
>= 0)
634 posix_spawn_file_actions_adddup2(&actions
, sidefd
, 4);
636 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Calling posix_spawn.");
638 if (posix_spawn(pid
, exec_path
, &actions
, &attrs
, argv
, envp
? envp
: environ
))
640 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
, strerror(errno
));
645 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: pid=%d", (int)*pid
);
647 posix_spawn_file_actions_destroy(&actions
);
648 posix_spawnattr_destroy(&attrs
);
652 * Block signals before forking...
657 if ((*pid
= fork()) == 0)
660 * Child process goes here; update stderr as needed...
666 errfd
= open("/dev/null", O_WRONLY
);
676 * Put this process in its own process group so that we can kill any child
677 * processes it creates.
681 if (!RunUser
&& setpgid(0, 0))
684 if (!RunUser
&& setpgrp())
686 # endif /* HAVE_SETPGID */
689 * Update the remaining file descriptors as needed...
695 infd
= open("/dev/null", O_RDONLY
);
707 outfd
= open("/dev/null", O_WRONLY
);
716 if (backfd
!= 3 && backfd
>= 0)
720 fcntl(3, F_SETFL
, O_NDELAY
);
723 if (sidefd
!= 4 && sidefd
>= 0)
727 fcntl(4, F_SETFL
, O_NDELAY
);
731 * Change the priority of the process based on the FilterNice setting.
732 * (this is not done for root processes...)
739 * Reset group membership to just the main one we belong to.
742 if (!RunUser
&& setgid(Group
))
745 if (!RunUser
&& setgroups(1, &Group
))
749 * Change user to something "safe"...
752 if (!RunUser
&& user
&& setuid(user
))
756 * Change umask to restrict permissions on created files...
762 * Unblock signals before doing the exec...
766 sigset(SIGTERM
, SIG_DFL
);
767 sigset(SIGCHLD
, SIG_DFL
);
768 sigset(SIGPIPE
, SIG_DFL
);
769 # elif defined(HAVE_SIGACTION)
770 memset(&action
, 0, sizeof(action
));
772 sigemptyset(&action
.sa_mask
);
773 action
.sa_handler
= SIG_DFL
;
775 sigaction(SIGTERM
, &action
, NULL
);
776 sigaction(SIGCHLD
, &action
, NULL
);
777 sigaction(SIGPIPE
, &action
, NULL
);
779 signal(SIGTERM
, SIG_DFL
);
780 signal(SIGCHLD
, SIG_DFL
);
781 signal(SIGPIPE
, SIG_DFL
);
782 # endif /* HAVE_SIGSET */
784 cupsdReleaseSignals();
787 * Execute the command; if for some reason this doesn't work, log an error
788 * exit with a non-zero value...
792 execve(exec_path
, argv
, envp
);
794 execv(exec_path
, argv
);
801 * Error - couldn't fork a new process!
804 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
,
810 cupsdReleaseSignals();
811 #endif /* USE_POSIX_SPAWN */
816 process_array
= cupsArrayNew((cups_array_func_t
)compare_procs
, NULL
);
820 if ((proc
= calloc(1, sizeof(cupsd_proc_t
) + strlen(command
))) != NULL
)
823 proc
->job_id
= job
? job
->id
: 0;
824 _cups_strcpy(proc
->name
, command
);
826 cupsArrayAdd(process_array
, proc
);
831 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
832 "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
833 "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
834 "profile=%p, job=%p(%d), pid=%p) = %d",
835 command
, argv
, envp
, infd
, outfd
, errfd
, backfd
, sidefd
,
836 root
, profile
, job
, job
? job
->id
: 0, pid
, *pid
);
843 * 'compare_procs()' - Compare two processes.
846 static int /* O - Result of comparison */
847 compare_procs(cupsd_proc_t
*a
, /* I - First process */
848 cupsd_proc_t
*b
) /* I - Second process */
850 return (a
->pid
- b
->pid
);
854 #ifdef HAVE_SANDBOX_H
856 * 'cupsd_requote()' - Make a regular-expression version of a string.
859 static char * /* O - Quoted string */
860 cupsd_requote(char *dst
, /* I - Destination buffer */
861 const char *src
, /* I - Source string */
862 size_t dstsize
) /* I - Size of destination buffer */
864 int ch
; /* Current character */
865 char *dstptr
, /* Current position in buffer */
866 *dstend
; /* End of destination buffer */
870 dstend
= dst
+ dstsize
- 2;
872 while (*src
&& dstptr
< dstend
)
876 if (ch
== '/' && !*src
)
877 break; /* Don't add trailing slash */
879 if (strchr(".?*()[]^$\\", ch
))
882 *dstptr
++ = (char)ch
;
889 #endif /* HAVE_SANDBOX_H */
893 * End of "$Id: process.c 13138 2016-03-15 14:59:54Z msweet $".