2 * "$Id: process.c 12034 2014-07-16 19:37:34Z msweet $"
4 * Process management routines for the CUPS scheduler.
6 * Copyright 2007-2014 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 */
32 * Process structure...
37 int pid
, /* Process ID */
38 job_id
; /* Job associated with process */
39 char name
[1]; /* Name of process */
47 static cups_array_t
*process_array
= NULL
;
54 static int compare_procs(cupsd_proc_t
*a
, cupsd_proc_t
*b
);
56 static char *cupsd_requote(char *dst
, const char *src
, size_t dstsize
);
57 #endif /* HAVE_SANDBOX_H */
61 * 'cupsdCreateProfile()' - Create an execution profile for a subprocess.
64 void * /* O - Profile or NULL on error */
65 cupsdCreateProfile(int job_id
, /* I - Job ID or 0 for none */
66 int allow_networking
)/* I - Allow networking off machine? */
69 cups_file_t
*fp
; /* File pointer */
70 char profile
[1024], /* File containing the profile */
71 bin
[1024], /* Quoted ServerBin */
72 cache
[1024], /* Quoted CacheDir */
73 domain
[1024], /* Domain socket, if any */
74 request
[1024], /* Quoted RequestRoot */
75 root
[1024], /* Quoted ServerRoot */
76 state
[1024], /* Quoted StateDir */
77 temp
[1024]; /* Quoted TempDir */
78 const char *nodebug
; /* " (with no-log)" for no debug */
79 cupsd_listener_t
*lis
; /* Current listening socket */
82 if (!UseSandboxing
|| Sandboxing
== CUPSD_SANDBOXING_OFF
)
85 * Only use sandbox profiles as root...
88 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
93 if ((fp
= cupsTempFile2(profile
, sizeof(profile
))) == NULL
)
95 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
96 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to create security profile: %s",
101 fchown(cupsFileNumber(fp
), RunUser
, Group
);
102 fchmod(cupsFileNumber(fp
), 0640);
104 cupsd_requote(bin
, ServerBin
, sizeof(bin
));
105 cupsd_requote(cache
, CacheDir
, sizeof(cache
));
106 cupsd_requote(request
, RequestRoot
, sizeof(request
));
107 cupsd_requote(root
, ServerRoot
, sizeof(root
));
108 cupsd_requote(state
, StateDir
, sizeof(state
));
109 cupsd_requote(temp
, TempDir
, sizeof(temp
));
111 nodebug
= LogLevel
< CUPSD_LOG_DEBUG
? " (with no-log)" : "";
113 cupsFilePuts(fp
, "(version 1)\n");
114 if (Sandboxing
== CUPSD_SANDBOXING_STRICT
)
115 cupsFilePuts(fp
, "(deny default)\n");
117 cupsFilePuts(fp
, "(allow default)\n");
118 if (LogLevel
>= CUPSD_LOG_DEBUG
)
119 cupsFilePuts(fp
, "(debug deny)\n");
120 cupsFilePuts(fp
, "(import \"system.sb\")\n");
121 cupsFilePuts(fp
, "(system-network)\n");
122 cupsFilePuts(fp
, "(allow mach-per-user-lookup)\n");
123 cupsFilePuts(fp
, "(allow ipc-posix-sem)\n");
124 cupsFilePuts(fp
, "(allow ipc-posix-shm)\n");
125 cupsFilePuts(fp
, "(allow ipc-sysv-shm)\n");
126 cupsFilePuts(fp
, "(allow mach-lookup)\n");
129 "(deny file-write* file-read-data file-read-metadata\n"
135 "(deny file-write*\n"
137 " #\"^%s$\"" /* ServerRoot */
138 " #\"^%s/\"" /* ServerRoot/... */
139 " #\"^/private/etc$\""
140 " #\"^/private/etc/\""
141 " #\"^/usr/local/etc$\""
142 " #\"^/usr/local/etc/\""
148 root
, root
, nodebug
);
149 /* Specifically allow applications to stat RequestRoot and some other system folders */
151 "(allow file-read-metadata\n"
154 " #\"^/usr$\"" /* /usr */
155 " #\"^/Library$\"" /* /Library */
156 " #\"^/Library/Printers$\"" /* /Library/Printers */
157 " #\"^%s$\"" /* RequestRoot */
160 /* Read and write TempDir, CacheDir, and other common folders */
162 "(allow file-write* file-read-data file-read-metadata\n"
164 " #\"^/private/var/db/\""
165 " #\"^/private/var/folders/\""
166 " #\"^/private/var/lib/\""
167 " #\"^/private/var/log/\""
168 " #\"^/private/var/mysql/\""
169 " #\"^/private/var/run/\""
170 " #\"^/private/var/spool/\""
171 " #\"^/Library/Application Support/\""
172 " #\"^/Library/Caches/\""
173 " #\"^/Library/Logs/\""
174 " #\"^/Library/Preferences/\""
175 " #\"^/Library/WebServer/\""
176 " #\"^/Users/Shared/\""
179 "(deny file-write*\n"
180 " (regex #\"^%s$\")%s)\n",
183 "(deny file-write* file-read-data file-read-metadata\n"
184 " (regex #\"^%s/\")%s)\n",
187 "(allow file-write* file-read-data file-read-metadata\n"
189 " #\"^%s$\"" /* TempDir */
190 " #\"^%s/\"" /* TempDir/... */
191 " #\"^%s$\"" /* CacheDir */
192 " #\"^%s/\"" /* CacheDir/... */
193 " #\"^%s$\"" /* StateDir */
194 " #\"^%s/\"" /* StateDir/... */
196 temp
, temp
, cache
, cache
, state
, state
);
197 /* Read common folders */
199 "(allow file-read-data file-read-metadata\n"
201 " #\"^/AppleInternal$\""
202 " #\"^/AppleInternal/\""
203 " #\"^/bin$\"" /* /bin */
204 " #\"^/bin/\"" /* /bin/... */
206 " #\"^/private/etc$\""
207 " #\"^/private/etc/\""
208 " #\"^/private/tmp$\""
209 " #\"^/private/tmp/\""
210 " #\"^/private/var$\""
211 " #\"^/private/var/db$\""
212 " #\"^/private/var/folders$\""
213 " #\"^/private/var/lib$\""
214 " #\"^/private/var/log$\""
215 " #\"^/private/var/mysql$\""
216 " #\"^/private/var/run$\""
217 " #\"^/private/var/spool$\""
218 " #\"^/usr/bin$\"" /* /usr/bin */
219 " #\"^/usr/bin/\"" /* /usr/bin/... */
220 " #\"^/usr/libexec/cups$\"" /* /usr/libexec/cups */
221 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
222 " #\"^/usr/libexec/fax$\"" /* /usr/libexec/fax */
223 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
224 " #\"^/usr/sbin$\"" /* /usr/sbin */
225 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
226 " #\"^/Library/Application Support$\""
227 " #\"^/Library/Application Support/\""
228 " #\"^/Library/Caches$\""
229 " #\"^/Library/ColorSync$\""
230 " #\"^/Library/ColorSync/Profiles$\""
231 " #\"^/Library/ColorSync/Profiles/\""
232 " #\"^/Library/Fonts$\""
233 " #\"^/Library/Fonts/\""
234 " #\"^/Library/Frameworks$\""
235 " #\"^/Library/Frameworks/\""
236 " #\"^/Library/Keychains$\""
237 " #\"^/Library/Keychains/\""
238 " #\"^/Library/Logs$\""
239 " #\"^/Library/Printers$\""
240 " #\"^/Library/Printers/\""
241 " #\"^/Library/Security$\""
242 " #\"^/Library/Security/\""
243 " #\"^/Library/WebServer$\""
244 " #\"^/System/Library/ColorSync$\""
245 " #\"^/System/Library/ColorSync/Profiles$\""
246 " #\"^/System/Library/ColorSync/Profiles/\""
247 " #\"^%s/Library$\"" /* RequestRoot/Library */
248 " #\"^%s/Library/\"" /* RequestRoot/Library/... */
249 " #\"^%s$\"" /* ServerBin */
250 " #\"^%s/\"" /* ServerBin/... */
251 " #\"^%s$\"" /* ServerRoot */
252 " #\"^%s/\"" /* ServerRoot/... */
254 request
, request
, bin
, bin
, root
, root
);
255 if (Sandboxing
== CUPSD_SANDBOXING_RELAXED
)
257 /* Limited write access to /Library/Printers/... */
259 "(allow file-write*\n"
261 " #\"^/Library/Printers/.*/\""
264 "(deny file-write*\n"
266 " #\"^/Library/Printers/PPDs$\""
267 " #\"^/Library/Printers/PPDs/\""
268 " #\"^/Library/Printers/PPD Plugins$\""
269 " #\"^/Library/Printers/PPD Plugins/\""
272 /* Allow execution of child processes as long as the programs are not in a user directory */
273 cupsFilePuts(fp
, "(allow process*)\n");
274 cupsFilePuts(fp
, "(deny process-exec (regex #\"^/Users/\"))\n");
275 if (RunUser
&& getenv("CUPS_TESTROOT"))
277 /* Allow source directory access in "make test" environment */
278 char testroot
[1024]; /* Root directory of test files */
280 cupsd_requote(testroot
, getenv("CUPS_TESTROOT"), sizeof(testroot
));
283 "(allow file-write* file-read-data file-read-metadata\n"
285 " #\"^%s$\"" /* CUPS_TESTROOT */
286 " #\"^%s/\"" /* CUPS_TESTROOT/... */
290 "(allow process-exec\n"
292 " #\"^%s/\"" /* CUPS_TESTROOT/... */
298 /* Allow job filters to read the current job files... */
300 "(allow file-read-data file-read-metadata\n"
301 " (regex #\"^%s/([ac]%05d|d%05d-[0-9][0-9][0-9])$\"))\n",
302 request
, job_id
, job_id
);
306 /* Allow email notifications from notifiers... */
308 "(allow process-exec\n"
309 " (literal \"/usr/sbin/sendmail\")\n"
310 " (with no-sandbox))\n");
312 /* Allow access to Bluetooth, USB, and notify_post. */
313 cupsFilePuts(fp
, "(allow iokit*)\n");
314 cupsFilePuts(fp
, "(allow distributed-notification-post)\n");
315 /* Allow outbound networking to local services */
316 cupsFilePuts(fp
, "(allow network-outbound"
317 "\n (regex #\"^/private/var/run/\" #\"^/private/tmp/\")");
318 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
320 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
322 if (httpAddrFamily(&(lis
->address
)) == AF_LOCAL
)
324 httpAddrString(&(lis
->address
), domain
, sizeof(domain
));
325 cupsFilePrintf(fp
, "\n (literal \"%s\")", domain
);
328 if (allow_networking
)
330 /* Allow TCP and UDP networking off the machine... */
331 cupsFilePuts(fp
, "\n (remote tcp))\n");
332 cupsFilePuts(fp
, "(allow network-bind)\n"); /* for LPD resvport */
333 cupsFilePuts(fp
, "(allow network*\n"
334 " (local udp \"*:*\")\n"
335 " (remote udp \"*:*\"))\n");
337 /* Also allow access to device files... */
338 cupsFilePuts(fp
, "(allow file-write* file-read-data file-read-metadata file-ioctl\n"
339 " (regex #\"^/dev/\"))\n");
343 /* Only allow SNMP (UDP) and LPD (TCP) off the machine... */
344 cupsFilePuts(fp
, ")\n");
345 cupsFilePuts(fp
, "(allow network-outbound\n"
346 " (remote udp \"*:161\")"
347 " (remote tcp \"*:515\"))\n");
348 cupsFilePuts(fp
, "(allow network-inbound\n"
349 " (local udp \"localhost:*\"))\n");
353 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d,allow_networking=%d) = \"%s\"", job_id
, allow_networking
, profile
);
354 return ((void *)strdup(profile
));
357 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
360 #endif /* HAVE_SANDBOX_H */
365 * 'cupsdDestroyProfile()' - Delete an execution profile.
369 cupsdDestroyProfile(void *profile
) /* I - Profile */
371 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeleteProfile(profile=\"%s\")",
372 profile
? (char *)profile
: "(null)");
374 #ifdef HAVE_SANDBOX_H
377 unlink((char *)profile
);
380 #endif /* HAVE_SANDBOX_H */
385 * 'cupsdEndProcess()' - End a process.
388 int /* O - 0 on success, -1 on failure */
389 cupsdEndProcess(int pid
, /* I - Process ID */
390 int force
) /* I - Force child to die */
392 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdEndProcess(pid=%d, force=%d)", pid
,
401 * When running as root, cupsd puts child processes in their own process
402 * group. Using "-pid" sends a signal to all processes in the group.
409 return (kill(pid
, SIGKILL
));
411 return (kill(pid
, SIGTERM
));
416 * 'cupsdFinishProcess()' - Finish a process and get its name.
419 const char * /* O - Process name */
420 cupsdFinishProcess(int pid
, /* I - Process ID */
421 char *name
, /* I - Name buffer */
422 size_t namelen
, /* I - Size of name buffer */
423 int *job_id
) /* O - Job ID pointer or NULL */
425 cupsd_proc_t key
, /* Search key */
426 *proc
; /* Matching process */
431 if ((proc
= (cupsd_proc_t
*)cupsArrayFind(process_array
, &key
)) != NULL
)
434 *job_id
= proc
->job_id
;
436 strlcpy(name
, proc
->name
, namelen
);
437 cupsArrayRemove(process_array
, proc
);
445 strlcpy(name
, "unknown", namelen
);
448 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
);
455 * 'cupsdStartProcess()' - Start a process.
458 int /* O - Process ID or 0 */
460 const char *command
, /* I - Full path to command */
461 char *argv
[], /* I - Command-line arguments */
462 char *envp
[], /* I - Environment */
463 int infd
, /* I - Standard input file descriptor */
464 int outfd
, /* I - Standard output file descriptor */
465 int errfd
, /* I - Standard error file descriptor */
466 int backfd
, /* I - Backchannel file descriptor */
467 int sidefd
, /* I - Sidechannel file descriptor */
468 int root
, /* I - Run as root? */
469 void *profile
, /* I - Security profile to use */
470 cupsd_job_t
*job
, /* I - Job associated with process */
471 int *pid
) /* O - Process ID */
473 int i
; /* Looping var */
474 const char *exec_path
= command
; /* Command to be exec'd */
475 char *real_argv
[110], /* Real command-line arguments */
476 cups_exec
[1024]; /* Path to "cups-exec" program */
477 uid_t user
; /* Command UID */
478 cupsd_proc_t
*proc
; /* New process record */
479 #ifdef HAVE_POSIX_SPAWN
480 posix_spawn_file_actions_t actions
; /* Spawn file actions */
481 posix_spawnattr_t attrs
; /* Spawn attributes */
482 char user_str
[16], /* User string */
483 group_str
[16], /* Group string */
484 nice_str
[16]; /* FilterNice string */
485 #elif defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
486 struct sigaction action
; /* POSIX signal handler */
487 #endif /* HAVE_POSIX_SPAWN */
488 #if defined(__APPLE__)
489 char processPath
[1024], /* CFProcessPath environment variable */
490 linkpath
[1024]; /* Link path for symlinks... */
491 int linkbytes
; /* Bytes for link path */
492 #endif /* __APPLE__ */
498 * Figure out the UID for the child process...
509 * Check the permissions of the command we are running...
512 if (_cupsFileCheck(command
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
513 cupsdLogFCMessage
, job
? job
->printer
: NULL
))
516 #if defined(__APPLE__)
520 * Add special voodoo magic for OS X - this allows OS X programs to access
521 * their bundle resources properly...
524 if ((linkbytes
= readlink(command
, linkpath
, sizeof(linkpath
) - 1)) > 0)
527 * Yes, this is a symlink to the actual program, nul-terminate and
531 linkpath
[linkbytes
] = '\0';
533 if (linkpath
[0] == '/')
534 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s",
537 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s/%s",
538 dirname((char *)command
), linkpath
);
541 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s", command
);
543 envp
[0] = processPath
; /* Replace <CFProcessPath> string */
545 #endif /* __APPLE__ */
548 * Use helper program when we have a sandbox profile...
551 #ifndef HAVE_POSIX_SPAWN
553 #endif /* !HAVE_POSIX_SPAWN */
555 snprintf(cups_exec
, sizeof(cups_exec
), "%s/daemon/cups-exec", ServerBin
);
556 snprintf(user_str
, sizeof(user_str
), "%d", user
);
557 snprintf(group_str
, sizeof(group_str
), "%d", Group
);
558 snprintf(nice_str
, sizeof(nice_str
), "%d", FilterNice
);
560 real_argv
[0] = cups_exec
;
561 real_argv
[1] = (char *)"-g";
562 real_argv
[2] = group_str
;
563 real_argv
[3] = (char *)"-n";
564 real_argv
[4] = nice_str
;
565 real_argv
[5] = (char *)"-u";
566 real_argv
[6] = user_str
;
567 real_argv
[7] = profile
? profile
: "none";
568 real_argv
[8] = (char *)command
;
571 i
< (int)(sizeof(real_argv
) / sizeof(real_argv
[0]) - 10) && argv
[i
];
573 real_argv
[i
+ 9] = argv
[i
];
575 real_argv
[i
+ 9] = NULL
;
578 exec_path
= cups_exec
;
581 if (LogLevel
== CUPSD_LOG_DEBUG2
)
583 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Preparing to start \"%s\", arguments:", command
);
585 for (i
= 0; argv
[i
]; i
++)
586 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: argv[%d] = \"%s\"", i
, argv
[i
]);
589 #ifdef HAVE_POSIX_SPAWN
591 * Setup attributes and file actions for the spawn...
594 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting spawn attributes.");
595 posix_spawnattr_init(&attrs
);
596 posix_spawnattr_setflags(&attrs
, POSIX_SPAWN_SETPGROUP
| POSIX_SPAWN_SETSIGDEF
);
598 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting file actions.");
599 posix_spawn_file_actions_init(&actions
);
603 posix_spawn_file_actions_addopen(&actions
, 0, "/dev/null", O_WRONLY
, 0);
605 posix_spawn_file_actions_adddup2(&actions
, infd
, 0);
611 posix_spawn_file_actions_addopen(&actions
, 1, "/dev/null", O_WRONLY
, 0);
613 posix_spawn_file_actions_adddup2(&actions
, outfd
, 1);
619 posix_spawn_file_actions_addopen(&actions
, 2, "/dev/null", O_WRONLY
, 0);
621 posix_spawn_file_actions_adddup2(&actions
, errfd
, 2);
624 if (backfd
!= 3 && backfd
>= 0)
625 posix_spawn_file_actions_adddup2(&actions
, backfd
, 3);
627 if (sidefd
!= 4 && sidefd
>= 0)
628 posix_spawn_file_actions_adddup2(&actions
, sidefd
, 4);
630 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Calling posix_spawn.");
632 if (posix_spawn(pid
, exec_path
, &actions
, &attrs
, argv
, envp
? envp
: environ
))
634 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
, strerror(errno
));
639 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: pid=%d", (int)*pid
);
641 posix_spawn_file_actions_destroy(&actions
);
642 posix_spawnattr_destroy(&attrs
);
646 * Block signals before forking...
651 if ((*pid
= fork()) == 0)
654 * Child process goes here; update stderr as needed...
660 errfd
= open("/dev/null", O_WRONLY
);
670 * Put this process in its own process group so that we can kill any child
671 * processes it creates.
675 if (!RunUser
&& setpgid(0, 0))
678 if (!RunUser
&& setpgrp())
680 # endif /* HAVE_SETPGID */
683 * Update the remaining file descriptors as needed...
689 infd
= open("/dev/null", O_RDONLY
);
701 outfd
= open("/dev/null", O_WRONLY
);
710 if (backfd
!= 3 && backfd
>= 0)
714 fcntl(3, F_SETFL
, O_NDELAY
);
717 if (sidefd
!= 4 && sidefd
>= 0)
721 fcntl(4, F_SETFL
, O_NDELAY
);
725 * Change the priority of the process based on the FilterNice setting.
726 * (this is not done for root processes...)
733 * Reset group membership to just the main one we belong to.
736 if (!RunUser
&& setgid(Group
))
739 if (!RunUser
&& setgroups(1, &Group
))
743 * Change user to something "safe"...
746 if (!RunUser
&& user
&& setuid(user
))
750 * Change umask to restrict permissions on created files...
756 * Unblock signals before doing the exec...
760 sigset(SIGTERM
, SIG_DFL
);
761 sigset(SIGCHLD
, SIG_DFL
);
762 sigset(SIGPIPE
, SIG_DFL
);
763 # elif defined(HAVE_SIGACTION)
764 memset(&action
, 0, sizeof(action
));
766 sigemptyset(&action
.sa_mask
);
767 action
.sa_handler
= SIG_DFL
;
769 sigaction(SIGTERM
, &action
, NULL
);
770 sigaction(SIGCHLD
, &action
, NULL
);
771 sigaction(SIGPIPE
, &action
, NULL
);
773 signal(SIGTERM
, SIG_DFL
);
774 signal(SIGCHLD
, SIG_DFL
);
775 signal(SIGPIPE
, SIG_DFL
);
776 # endif /* HAVE_SIGSET */
778 cupsdReleaseSignals();
781 * Execute the command; if for some reason this doesn't work, log an error
782 * exit with a non-zero value...
786 execve(exec_path
, argv
, envp
);
788 execv(exec_path
, argv
);
795 * Error - couldn't fork a new process!
798 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
,
804 cupsdReleaseSignals();
805 #endif /* HAVE_POSIX_SPAWN */
810 process_array
= cupsArrayNew((cups_array_func_t
)compare_procs
, NULL
);
814 if ((proc
= calloc(1, sizeof(cupsd_proc_t
) + strlen(command
))) != NULL
)
817 proc
->job_id
= job
? job
->id
: 0;
818 _cups_strcpy(proc
->name
, command
);
820 cupsArrayAdd(process_array
, proc
);
825 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
826 "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
827 "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
828 "profile=%p, job=%p(%d), pid=%p) = %d",
829 command
, argv
, envp
, infd
, outfd
, errfd
, backfd
, sidefd
,
830 root
, profile
, job
, job
? job
->id
: 0, pid
, *pid
);
837 * 'compare_procs()' - Compare two processes.
840 static int /* O - Result of comparison */
841 compare_procs(cupsd_proc_t
*a
, /* I - First process */
842 cupsd_proc_t
*b
) /* I - Second process */
844 return (a
->pid
- b
->pid
);
848 #ifdef HAVE_SANDBOX_H
850 * 'cupsd_requote()' - Make a regular-expression version of a string.
853 static char * /* O - Quoted string */
854 cupsd_requote(char *dst
, /* I - Destination buffer */
855 const char *src
, /* I - Source string */
856 size_t dstsize
) /* I - Size of destination buffer */
858 int ch
; /* Current character */
859 char *dstptr
, /* Current position in buffer */
860 *dstend
; /* End of destination buffer */
864 dstend
= dst
+ dstsize
- 2;
866 while (*src
&& dstptr
< dstend
)
870 if (ch
== '/' && !*src
)
871 break; /* Don't add trailing slash */
873 if (strchr(".?*()[]^$\\", ch
))
876 *dstptr
++ = (char)ch
;
883 #endif /* HAVE_SANDBOX_H */
887 * End of "$Id: process.c 12034 2014-07-16 19:37:34Z msweet $".