2
0

MkDir.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $TOG: MkDir.c /main/8 1999/12/09 13:06:55 mgreess $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: MkDir.c
  28. *
  29. * COMPONENT_NAME: Desktop File Manager (dtfile)
  30. *
  31. * Description: Contains functions to make directories.
  32. *
  33. * FUNCTIONS: RunFileCommand
  34. *
  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.
  39. *
  40. ****************************************************************************
  41. ************************************<+>*************************************/
  42. #include <sys/param.h>
  43. #include <sys/types.h>
  44. #include <fcntl.h>
  45. #include <sys/stat.h>
  46. #include <signal.h>
  47. #include <errno.h>
  48. #include <sys/wait.h>
  49. #include <unistd.h>
  50. #include <limits.h>
  51. #ifdef __hpux
  52. #include <sys/getaccess.h>
  53. #endif
  54. #include <Xm/Xm.h>
  55. #include <Dt/EnvControlP.h>
  56. #include <Dt/DtNlUtils.h>
  57. #include "Encaps.h"
  58. #include "FileMgr.h"
  59. #include "Desktop.h"
  60. #include "Main.h"
  61. /************************************************************************
  62. *
  63. * RunFileCommand
  64. * This function is called to fork a process and run a command in the
  65. * event that PAM does not have the appropriate capabilities (i.e. PAM
  66. * isn't superuser and superuser privilege is required). PAM waits
  67. * for completion of the forked command process.
  68. *
  69. * PARAMETERS:
  70. *
  71. * command_path -- this is a pointer to the full pathname of the
  72. * command to be run.
  73. *
  74. * argument1 -- this is a pointer to the first command argument.
  75. *
  76. * argument2 -- this is a pointer to the second command argument.
  77. *
  78. * argument3 -- this is a pointer to the third command argument.
  79. *
  80. * RETURN VALUE:
  81. *
  82. * If the command could not be run or if it exited with a non-zero
  83. * value then a non-zero value is returned.
  84. *
  85. ************************************************************************/
  86. int
  87. RunFileCommand(
  88. char *command_path,
  89. char *argument1,
  90. char *argument2,
  91. char *argument3)
  92. {
  93. static char *pname = "RunFileCommand";
  94. int child; /* process id of command process */
  95. int wait_return; /* return value from wait */
  96. int exit_value; /* command exit value */
  97. char *command_name; /* pointer to the command name */
  98. int i;
  99. void (*oldSig)();
  100. /* prepare to catch the command termination */
  101. oldSig = signal (SIGCHLD, SIG_DFL);
  102. /* fork a process to run command */
  103. if ((child = fork ()) < 0) /* fork failed */
  104. {
  105. (void) signal (SIGCHLD, oldSig);
  106. return (-1);
  107. }
  108. if (child != 0) /* parend (PAM) process */
  109. {
  110. DBGFORK(("%s: forked child<%d>\n", pname, child));
  111. do /* wait for completion of command */
  112. {
  113. wait_return = wait (&exit_value);
  114. } while (wait_return != child);
  115. (void) signal (SIGCHLD, oldSig); /* child stopped or terminated */
  116. return (exit_value); /* if exit_value == 0 then success */
  117. }
  118. DBGFORK(("%s: child forked\n", pname));
  119. /* child (command) process */
  120. /* redirect stdin, stdout, stderr to /dev/null */
  121. for (i = 0; i < 3; i++)
  122. {
  123. (void) close (i);
  124. (void) open ("/dev/null", O_RDWR);
  125. }
  126. /* set pointer to simple command name */
  127. if ((command_name = (char *)strrchr (command_path, '/')) == 0)
  128. command_name = command_path;
  129. else
  130. command_name++;
  131. _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
  132. (void) execl (command_path, command_name, argument1, argument2, argument3,0);
  133. DBGFORK(("%s: child exiting\n", pname));
  134. exit (-1); /* error exit */
  135. }