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 librararies 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>
54 #include <sys/getaccess.h>
59 #include <Dt/EnvControlP.h>
60 #include <Dt/DtNlUtils.h>
67 /************************************************************************
70 * This function is called to fork a process and run a command in the
71 * event that PAM does not have the appropriate capabilities (i.e. PAM
72 * isn't superuser and superuser privilege is required). PAM waits
73 * for completion of the forked command process.
77 * command_path -- this is a pointer to the full pathname of the
80 * argument1 -- this is a pointer to the first command argument.
82 * argument2 -- this is a pointer to the second command argument.
84 * argument3 -- this is a pointer to the third command argument.
88 * If the command could not be run or if it exited with a non-zero
89 * value then a non-zero value is returned.
91 ************************************************************************/
95 register char *command_path,
96 register char *argument1,
97 register char *argument2,
98 register char *argument3)
100 static char *pname = "RunFileCommand";
101 register int child; /* process id of command process */
102 register int wait_return; /* return value from wait */
103 int exit_value; /* command exit value */
104 register char *command_name; /* pointer to the command name */
108 /* prepare to catch the command termination */
110 oldSig = signal (SIGCLD, SIG_DFL);
112 /* fork a process to run command */
114 if ((child = fork ()) < 0) /* fork failed */
116 (void) signal (SIGCLD, oldSig);
120 if (child != 0) /* parend (PAM) process */
122 DBGFORK(("%s: forked child<%d>\n", pname, child));
124 do /* wait for completion of command */
126 wait_return = wait (&exit_value);
127 } while (wait_return != child);
129 (void) signal (SIGCLD, oldSig); /* child stopped or terminated */
131 return (exit_value); /* if exit_value == 0 then success */
135 DBGFORK(("%s: child forked\n", pname));
137 /* child (command) process */
139 /* redirect stdin, stdout, stderr to /dev/null */
141 for (i = 0; i < 3; i++)
144 (void) open ("/dev/null", O_RDWR);
148 /* set pointer to simple command name */
150 if ((command_name = (char *)strrchr (command_path, '/')) == 0)
151 command_name = command_path;
155 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
156 (void) execl (command_path, command_name, argument1, argument2, argument3,0);
158 DBGFORK(("%s: child exiting\n", pname));
160 exit (-1); /* error exit */