/[projects]/smsdaemon/Util.cpp
ViewVC logotype

Diff of /smsdaemon/Util.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 196 by torben, Thu Dec 18 06:53:29 2008 UTC revision 203 by torben, Fri Dec 19 07:03:34 2008 UTC
# Line 10  Line 10 
10  #include <stdexcept>  #include <stdexcept>
11  #include <time.h>  #include <time.h>
12  #include <sys/time.h>  #include <sys/time.h>
13    #include <sys/types.h>
14    #include <sys/wait.h>
15    #include <errno.h>
16  #include <stdlib.h>  #include <stdlib.h>
17    
18  #include <cstring>  #include <cstring>
# Line 420  namespace Util Line 423  namespace Util
423                  return (pclose(p));                  return (pclose(p));
424          }          }
425    
426            int my_system2 (const char *command)
427            {
428                    int pid, status;
429    
430                    if (command == 0)
431                            return 1;
432            //      printf("forking ...\n");
433                    pid = fork();
434                    if (pid == -1)
435                            return -1;
436                    if (pid == 0)
437                    {
438                            char *argv[4];
439                            argv[0] = (char*) "sh";
440                            argv[1] = (char*) "-c";
441                            argv[2] = (char *) command;
442                            argv[3] = 0;
443            //              printf("chaining ...\n");
444                            execve("/bin/sh", argv, environ);
445            //              printf("Chaining failed!\n");
446                            exit(127);
447                    }
448                    do
449                    {
450            //              printf("Waiting on PID: %d\n",pid);
451                            if (waitpid(pid, &status, 0) == -1)
452                            {
453            //                      printf("erc: %d\n",errno);
454                                    if (errno != EINTR)
455                                            return -1;
456                            }
457                            else
458                            {
459            //                      printf("status: %d\n",status);
460                                    return status;
461                            }
462                    }
463                    while (1);
464            }
465    
466    
467          string readfile(string filename)          string readfile(string filename)
468          {          {
469                  string str;                  string str;

Legend:
Removed from v.196  
changed lines
  Added in v.203

  ViewVC Help
Powered by ViewVC 1.1.20