2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: MkDir.c /main/8 1999/12/09 13:06:55 mgreess $ */
24 /************************************<+>*************************************
25 ****************************************************************************
29 * COMPONENT_NAME: Desktop File Manager (dtfile)
31 * Description: Contains functions to make directories.
33 * FUNCTIONS: RunFileCommand
35 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
36 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
37 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
38 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
40 ****************************************************************************
41 ************************************<+>*************************************/
43 #include <sys/param.h>
44 #include <sys/types.h>
55 #include <sys/getaccess.h>
60 #include <Dt/EnvControlP.h>
61 #include <Dt/DtNlUtils.h>
68 /************************************************************************
71 * This function is called to fork a process and run a command in the
72 * event that PAM does not have the appropriate capabilities (i.e. PAM
73 * isn't superuser and superuser privilege is required). PAM waits
74 * for completion of the forked command process.
78 * command_path -- this is a pointer to the full pathname of the
81 * argument1 -- this is a pointer to the first command argument.
83 * argument2 -- this is a pointer to the second command argument.
85 * argument3 -- this is a pointer to the third command argument.
89 * If the command could not be run or if it exited with a non-zero
90 * value then a non-zero value is returned.
92 ************************************************************************/
101 static char *pname = "RunFileCommand";
102 int child; /* process id of command process */
103 int wait_return; /* return value from wait */
104 int exit_value; /* command exit value */
105 char *command_name; /* pointer to the command name */
109 /* prepare to catch the command termination */
111 oldSig = signal (SIGCHLD, SIG_DFL);
113 /* fork a process to run command */
115 if ((child = fork ()) < 0) /* fork failed */
117 (void) signal (SIGCHLD, oldSig);
121 if (child != 0) /* parend (PAM) process */
123 DBGFORK(("%s: forked child<%d>\n", pname, child));
125 do /* wait for completion of command */
127 wait_return = wait (&exit_value);
128 } while (wait_return != child);
130 (void) signal (SIGCHLD, oldSig); /* child stopped or terminated */
132 return (exit_value); /* if exit_value == 0 then success */
136 DBGFORK(("%s: child forked\n", pname));
138 /* child (command) process */
140 /* redirect stdin, stdout, stderr to /dev/null */
142 for (i = 0; i < 3; i++)
145 (void) open ("/dev/null", O_RDWR);
149 /* set pointer to simple command name */
151 if ((command_name = (char *)strrchr (command_path, '/')) == 0)
152 command_name = command_path;
156 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
157 (void) execl (command_path, command_name, argument1, argument2, argument3,0);
159 DBGFORK(("%s: child exiting\n", pname));
161 exit (-1); /* error exit */