2 * "$Id: process.c 12252 2014-11-14 17:14:45Z 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 " #\"^/private/var/tmp$\""
219 " #\"^/private/var/tmp/\""
220 " #\"^/usr/bin$\"" /* /usr/bin */
221 " #\"^/usr/bin/\"" /* /usr/bin/... */
222 " #\"^/usr/libexec/cups$\"" /* /usr/libexec/cups */
223 " #\"^/usr/libexec/cups/\"" /* /usr/libexec/cups/... */
224 " #\"^/usr/libexec/fax$\"" /* /usr/libexec/fax */
225 " #\"^/usr/libexec/fax/\"" /* /usr/libexec/fax/... */
226 " #\"^/usr/sbin$\"" /* /usr/sbin */
227 " #\"^/usr/sbin/\"" /* /usr/sbin/... */
228 " #\"^/Library$\"" /* /Library */
229 " #\"^/Library/\"" /* /Library/... */
230 " #\"^/System$\"" /* /System */
231 " #\"^/System/\"" /* /System/... */
232 " #\"^%s/Library$\"" /* RequestRoot/Library */
233 " #\"^%s/Library/\"" /* RequestRoot/Library/... */
234 " #\"^%s$\"" /* ServerBin */
235 " #\"^%s/\"" /* ServerBin/... */
236 " #\"^%s$\"" /* ServerRoot */
237 " #\"^%s/\"" /* ServerRoot/... */
239 request
, request
, bin
, bin
, root
, root
);
240 if (Sandboxing
== CUPSD_SANDBOXING_RELAXED
)
242 /* Limited write access to /Library/Printers/... */
244 "(allow file-write*\n"
246 " #\"^/Library/Printers/.*/\""
249 "(deny file-write*\n"
251 " #\"^/Library/Printers/PPDs$\""
252 " #\"^/Library/Printers/PPDs/\""
253 " #\"^/Library/Printers/PPD Plugins$\""
254 " #\"^/Library/Printers/PPD Plugins/\""
257 /* Allow execution of child processes as long as the programs are not in a user directory */
258 cupsFilePuts(fp
, "(allow process*)\n");
259 cupsFilePuts(fp
, "(deny process-exec (regex #\"^/Users/\"))\n");
260 if (RunUser
&& getenv("CUPS_TESTROOT"))
262 /* Allow source directory access in "make test" environment */
263 char testroot
[1024]; /* Root directory of test files */
265 cupsd_requote(testroot
, getenv("CUPS_TESTROOT"), sizeof(testroot
));
268 "(allow file-write* file-read-data file-read-metadata\n"
270 " #\"^%s$\"" /* CUPS_TESTROOT */
271 " #\"^%s/\"" /* CUPS_TESTROOT/... */
275 "(allow process-exec\n"
277 " #\"^%s/\"" /* CUPS_TESTROOT/... */
280 cupsFilePrintf(fp
, "(allow sysctl*)\n");
284 /* Allow job filters to read the current job files... */
286 "(allow file-read-data file-read-metadata\n"
287 " (regex #\"^%s/([ac]%05d|d%05d-[0-9][0-9][0-9])$\"))\n",
288 request
, job_id
, job_id
);
292 /* Allow email notifications from notifiers... */
294 "(allow process-exec\n"
295 " (literal \"/usr/sbin/sendmail\")\n"
296 " (with no-sandbox))\n");
298 /* Allow access to Bluetooth, USB, and notify_post. */
299 cupsFilePuts(fp
, "(allow iokit*)\n");
300 cupsFilePuts(fp
, "(allow distributed-notification-post)\n");
301 /* Allow outbound networking to local services */
302 cupsFilePuts(fp
, "(allow network-outbound"
303 "\n (regex #\"^/private/var/run/\" #\"^/private/tmp/\" #\"^/private/var/tmp/\")");
304 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
306 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
308 if (httpAddrFamily(&(lis
->address
)) == AF_LOCAL
)
310 httpAddrString(&(lis
->address
), domain
, sizeof(domain
));
311 cupsFilePrintf(fp
, "\n (literal \"%s\")", domain
);
314 if (allow_networking
)
316 /* Allow TCP and UDP networking off the machine... */
317 cupsFilePuts(fp
, "\n (remote tcp))\n");
318 cupsFilePuts(fp
, "(allow network-bind)\n"); /* for LPD resvport */
319 cupsFilePuts(fp
, "(allow network*\n"
320 " (local udp \"*:*\")\n"
321 " (remote udp \"*:*\"))\n");
323 /* Also allow access to device files... */
324 cupsFilePuts(fp
, "(allow file-write* file-read-data file-read-metadata file-ioctl\n"
325 " (regex #\"^/dev/\"))\n");
329 /* Only allow SNMP (UDP) and LPD (TCP) off the machine... */
330 cupsFilePuts(fp
, ")\n");
331 cupsFilePuts(fp
, "(allow network-outbound\n"
332 " (remote udp \"*:161\")"
333 " (remote tcp \"*:515\"))\n");
334 cupsFilePuts(fp
, "(allow network-inbound\n"
335 " (local udp \"localhost:*\"))\n");
339 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d,allow_networking=%d) = \"%s\"", job_id
, allow_networking
, profile
);
340 return ((void *)strdup(profile
));
343 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCreateProfile(job_id=%d, allow_networking=%d) = NULL", job_id
, allow_networking
);
346 #endif /* HAVE_SANDBOX_H */
351 * 'cupsdDestroyProfile()' - Delete an execution profile.
355 cupsdDestroyProfile(void *profile
) /* I - Profile */
357 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDeleteProfile(profile=\"%s\")",
358 profile
? (char *)profile
: "(null)");
360 #ifdef HAVE_SANDBOX_H
363 unlink((char *)profile
);
366 #endif /* HAVE_SANDBOX_H */
371 * 'cupsdEndProcess()' - End a process.
374 int /* O - 0 on success, -1 on failure */
375 cupsdEndProcess(int pid
, /* I - Process ID */
376 int force
) /* I - Force child to die */
378 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdEndProcess(pid=%d, force=%d)", pid
,
387 * When running as root, cupsd puts child processes in their own process
388 * group. Using "-pid" sends a signal to all processes in the group.
395 return (kill(pid
, SIGKILL
));
397 return (kill(pid
, SIGTERM
));
402 * 'cupsdFinishProcess()' - Finish a process and get its name.
405 const char * /* O - Process name */
406 cupsdFinishProcess(int pid
, /* I - Process ID */
407 char *name
, /* I - Name buffer */
408 size_t namelen
, /* I - Size of name buffer */
409 int *job_id
) /* O - Job ID pointer or NULL */
411 cupsd_proc_t key
, /* Search key */
412 *proc
; /* Matching process */
417 if ((proc
= (cupsd_proc_t
*)cupsArrayFind(process_array
, &key
)) != NULL
)
420 *job_id
= proc
->job_id
;
422 strlcpy(name
, proc
->name
, namelen
);
423 cupsArrayRemove(process_array
, proc
);
431 strlcpy(name
, "unknown", namelen
);
434 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
);
441 * 'cupsdStartProcess()' - Start a process.
444 int /* O - Process ID or 0 */
446 const char *command
, /* I - Full path to command */
447 char *argv
[], /* I - Command-line arguments */
448 char *envp
[], /* I - Environment */
449 int infd
, /* I - Standard input file descriptor */
450 int outfd
, /* I - Standard output file descriptor */
451 int errfd
, /* I - Standard error file descriptor */
452 int backfd
, /* I - Backchannel file descriptor */
453 int sidefd
, /* I - Sidechannel file descriptor */
454 int root
, /* I - Run as root? */
455 void *profile
, /* I - Security profile to use */
456 cupsd_job_t
*job
, /* I - Job associated with process */
457 int *pid
) /* O - Process ID */
459 int i
; /* Looping var */
460 const char *exec_path
= command
; /* Command to be exec'd */
461 char *real_argv
[110], /* Real command-line arguments */
462 cups_exec
[1024], /* Path to "cups-exec" program */
463 user_str
[16], /* User string */
464 group_str
[16], /* Group string */
465 nice_str
[16]; /* FilterNice string */
466 uid_t user
; /* Command UID */
467 cupsd_proc_t
*proc
; /* New process record */
468 #if defined(HAVE_POSIX_SPAWN) && !defined(__OpenBSD__)
469 posix_spawn_file_actions_t actions
; /* Spawn file actions */
470 posix_spawnattr_t attrs
; /* Spawn attributes */
471 sigset_t defsignals
; /* Default signals */
472 #elif defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
473 struct sigaction action
; /* POSIX signal handler */
474 #endif /* HAVE_POSIX_SPAWN && !__OpenBSD__ */
475 #if defined(__APPLE__)
476 char processPath
[1024], /* CFProcessPath environment variable */
477 linkpath
[1024]; /* Link path for symlinks... */
478 int linkbytes
; /* Bytes for link path */
479 #endif /* __APPLE__ */
485 * Figure out the UID for the child process...
496 * Check the permissions of the command we are running...
499 if (_cupsFileCheck(command
, _CUPS_FILE_CHECK_PROGRAM
, !RunUser
,
500 cupsdLogFCMessage
, job
? job
->printer
: NULL
))
503 #if defined(__APPLE__)
507 * Add special voodoo magic for OS X - this allows OS X programs to access
508 * their bundle resources properly...
511 if ((linkbytes
= readlink(command
, linkpath
, sizeof(linkpath
) - 1)) > 0)
514 * Yes, this is a symlink to the actual program, nul-terminate and
518 linkpath
[linkbytes
] = '\0';
520 if (linkpath
[0] == '/')
521 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s",
524 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s/%s",
525 dirname((char *)command
), linkpath
);
528 snprintf(processPath
, sizeof(processPath
), "CFProcessPath=%s", command
);
530 envp
[0] = processPath
; /* Replace <CFProcessPath> string */
532 #endif /* __APPLE__ */
535 * Use helper program when we have a sandbox profile...
538 #if !defined(HAVE_POSIX_SPAWN) || defined(__OpenBSD__)
540 #endif /* !HAVE_POSIX_SPAWN || __OpenBSD__ */
542 snprintf(cups_exec
, sizeof(cups_exec
), "%s/daemon/cups-exec", ServerBin
);
543 snprintf(user_str
, sizeof(user_str
), "%d", user
);
544 snprintf(group_str
, sizeof(group_str
), "%d", Group
);
545 snprintf(nice_str
, sizeof(nice_str
), "%d", FilterNice
);
547 real_argv
[0] = cups_exec
;
548 real_argv
[1] = (char *)"-g";
549 real_argv
[2] = group_str
;
550 real_argv
[3] = (char *)"-n";
551 real_argv
[4] = nice_str
;
552 real_argv
[5] = (char *)"-u";
553 real_argv
[6] = user_str
;
554 real_argv
[7] = profile
? profile
: "none";
555 real_argv
[8] = (char *)command
;
558 i
< (int)(sizeof(real_argv
) / sizeof(real_argv
[0]) - 10) && argv
[i
];
560 real_argv
[i
+ 9] = argv
[i
];
562 real_argv
[i
+ 9] = NULL
;
565 exec_path
= cups_exec
;
568 if (LogLevel
== CUPSD_LOG_DEBUG2
)
570 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Preparing to start \"%s\", arguments:", command
);
572 for (i
= 0; argv
[i
]; i
++)
573 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: argv[%d] = \"%s\"", i
, argv
[i
]);
576 #if defined(HAVE_POSIX_SPAWN) && !defined(__OpenBSD__) /* OpenBSD posix_spawn is busted with SETSIGDEF */
578 * Setup attributes and file actions for the spawn...
581 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting spawn attributes.");
582 sigemptyset(&defsignals
);
583 sigaddset(&defsignals
, SIGTERM
);
584 sigaddset(&defsignals
, SIGCHLD
);
585 sigaddset(&defsignals
, SIGPIPE
);
587 posix_spawnattr_init(&attrs
);
588 posix_spawnattr_setflags(&attrs
, POSIX_SPAWN_SETPGROUP
| POSIX_SPAWN_SETSIGDEF
);
589 posix_spawnattr_setpgroup(&attrs
, 0);
590 posix_spawnattr_setsigdefault(&attrs
, &defsignals
);
592 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Setting file actions.");
593 posix_spawn_file_actions_init(&actions
);
597 posix_spawn_file_actions_addopen(&actions
, 0, "/dev/null", O_WRONLY
, 0);
599 posix_spawn_file_actions_adddup2(&actions
, infd
, 0);
605 posix_spawn_file_actions_addopen(&actions
, 1, "/dev/null", O_WRONLY
, 0);
607 posix_spawn_file_actions_adddup2(&actions
, outfd
, 1);
613 posix_spawn_file_actions_addopen(&actions
, 2, "/dev/null", O_WRONLY
, 0);
615 posix_spawn_file_actions_adddup2(&actions
, errfd
, 2);
618 if (backfd
!= 3 && backfd
>= 0)
619 posix_spawn_file_actions_adddup2(&actions
, backfd
, 3);
621 if (sidefd
!= 4 && sidefd
>= 0)
622 posix_spawn_file_actions_adddup2(&actions
, sidefd
, 4);
624 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: Calling posix_spawn.");
626 if (posix_spawn(pid
, exec_path
, &actions
, &attrs
, argv
, envp
? envp
: environ
))
628 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
, strerror(errno
));
633 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdStartProcess: pid=%d", (int)*pid
);
635 posix_spawn_file_actions_destroy(&actions
);
636 posix_spawnattr_destroy(&attrs
);
640 * Block signals before forking...
645 if ((*pid
= fork()) == 0)
648 * Child process goes here; update stderr as needed...
654 errfd
= open("/dev/null", O_WRONLY
);
664 * Put this process in its own process group so that we can kill any child
665 * processes it creates.
669 if (!RunUser
&& setpgid(0, 0))
672 if (!RunUser
&& setpgrp())
674 # endif /* HAVE_SETPGID */
677 * Update the remaining file descriptors as needed...
683 infd
= open("/dev/null", O_RDONLY
);
695 outfd
= open("/dev/null", O_WRONLY
);
704 if (backfd
!= 3 && backfd
>= 0)
708 fcntl(3, F_SETFL
, O_NDELAY
);
711 if (sidefd
!= 4 && sidefd
>= 0)
715 fcntl(4, F_SETFL
, O_NDELAY
);
719 * Change the priority of the process based on the FilterNice setting.
720 * (this is not done for root processes...)
727 * Reset group membership to just the main one we belong to.
730 if (!RunUser
&& setgid(Group
))
733 if (!RunUser
&& setgroups(1, &Group
))
737 * Change user to something "safe"...
740 if (!RunUser
&& user
&& setuid(user
))
744 * Change umask to restrict permissions on created files...
750 * Unblock signals before doing the exec...
754 sigset(SIGTERM
, SIG_DFL
);
755 sigset(SIGCHLD
, SIG_DFL
);
756 sigset(SIGPIPE
, SIG_DFL
);
757 # elif defined(HAVE_SIGACTION)
758 memset(&action
, 0, sizeof(action
));
760 sigemptyset(&action
.sa_mask
);
761 action
.sa_handler
= SIG_DFL
;
763 sigaction(SIGTERM
, &action
, NULL
);
764 sigaction(SIGCHLD
, &action
, NULL
);
765 sigaction(SIGPIPE
, &action
, NULL
);
767 signal(SIGTERM
, SIG_DFL
);
768 signal(SIGCHLD
, SIG_DFL
);
769 signal(SIGPIPE
, SIG_DFL
);
770 # endif /* HAVE_SIGSET */
772 cupsdReleaseSignals();
775 * Execute the command; if for some reason this doesn't work, log an error
776 * exit with a non-zero value...
780 execve(exec_path
, argv
, envp
);
782 execv(exec_path
, argv
);
789 * Error - couldn't fork a new process!
792 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to fork %s - %s.", command
,
798 cupsdReleaseSignals();
799 #endif /* HAVE_POSIX_SPAWN && !__OpenBSD__ */
804 process_array
= cupsArrayNew((cups_array_func_t
)compare_procs
, NULL
);
808 if ((proc
= calloc(1, sizeof(cupsd_proc_t
) + strlen(command
))) != NULL
)
811 proc
->job_id
= job
? job
->id
: 0;
812 _cups_strcpy(proc
->name
, command
);
814 cupsArrayAdd(process_array
, proc
);
819 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
820 "cupsdStartProcess(command=\"%s\", argv=%p, envp=%p, "
821 "infd=%d, outfd=%d, errfd=%d, backfd=%d, sidefd=%d, root=%d, "
822 "profile=%p, job=%p(%d), pid=%p) = %d",
823 command
, argv
, envp
, infd
, outfd
, errfd
, backfd
, sidefd
,
824 root
, profile
, job
, job
? job
->id
: 0, pid
, *pid
);
831 * 'compare_procs()' - Compare two processes.
834 static int /* O - Result of comparison */
835 compare_procs(cupsd_proc_t
*a
, /* I - First process */
836 cupsd_proc_t
*b
) /* I - Second process */
838 return (a
->pid
- b
->pid
);
842 #ifdef HAVE_SANDBOX_H
844 * 'cupsd_requote()' - Make a regular-expression version of a string.
847 static char * /* O - Quoted string */
848 cupsd_requote(char *dst
, /* I - Destination buffer */
849 const char *src
, /* I - Source string */
850 size_t dstsize
) /* I - Size of destination buffer */
852 int ch
; /* Current character */
853 char *dstptr
, /* Current position in buffer */
854 *dstend
; /* End of destination buffer */
858 dstend
= dst
+ dstsize
- 2;
860 while (*src
&& dstptr
< dstend
)
864 if (ch
== '/' && !*src
)
865 break; /* Don't add trailing slash */
867 if (strchr(".?*()[]^$\\", ch
))
870 *dstptr
++ = (char)ch
;
877 #endif /* HAVE_SANDBOX_H */
881 * End of "$Id: process.c 12252 2014-11-14 17:14:45Z msweet $".