Changeset 211 for trunk/src/sh_extern.c
- Timestamp:
- Feb 3, 2009, 8:45:50 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_extern.c
r174 r211 31 31 * for debugging 32 32 */ 33 #if 034 #define PDGBFILE "/ pdbg."33 #if 1 34 #define PDGBFILE "/home/rainer/PROJECTS/samhain/devel/pdbg." 35 35 #endif 36 36 … … 532 532 SL_ENTER(_("sh_ext_pclose")); 533 533 534 PDBG C_OPEN;534 PDBG_OPEN; 535 535 PDBG_S(" -> pclose"); 536 536 (void) fflush(task->pipe); … … 773 773 } 774 774 775 /* Execute command, return first line of output 776 * ifconfig | grep -1 lo | tail -n 1 | sed s/.*inet addr:\([0-9.]*\)\(.*\)/\1/ 777 */ 778 char * sh_ext_popen_str (char * command) 779 { 780 sh_tas_t task; 781 struct sigaction new_act; 782 struct sigaction old_act; 783 char dir[SH_PATHBUF]; 784 char * p; 785 char * out = NULL; 786 int status; 787 788 SL_ENTER(_("sh_ext_popen_str")); 789 790 sh_ext_tas_init(&task); 791 792 (void) sh_ext_tas_add_envv (&task, _("SHELL"), 793 _("/bin/sh")); 794 (void) sh_ext_tas_add_envv (&task, _("PATH"), 795 _("/sbin:/bin:/usr/sbin:/usr/bin:/usr/ucb")); 796 (void) sh_ext_tas_add_envv (&task, _("IFS"), " \n\t"); 797 if (sh.timezone != NULL) 798 { 799 (void) sh_ext_tas_add_envv(&task, "TZ", sh.timezone); 800 } 801 802 sh_ext_tas_command(&task, _("/bin/sh")); 803 804 (void) sh_ext_tas_add_argv(&task, _("/bin/sh")); 805 (void) sh_ext_tas_add_argv(&task, _("-c")); 806 (void) sh_ext_tas_add_argv(&task, command); 807 808 task.rw = 'r'; 809 task.fork_twice = S_FALSE; 810 811 status = sh_ext_popen(&task); 812 813 if (status != 0) 814 { 815 sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, status, MSG_E_SUBGEN, 816 _("Could not open pipe"), _("sh_ext_popen_str")); 817 SL_RETURN ((NULL), _("sh_ext_popen_str")); 818 } 819 820 /* ignore SIGPIPE (instead get EPIPE if connection is closed) 821 */ 822 new_act.sa_handler = SIG_IGN; 823 (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act); 824 825 /* read from the open pipe 826 */ 827 if (task.pipe != NULL) 828 { 829 int try = 1200; /* 1000 * 0.1 = 120 sec */ 830 sh_string * s = sh_string_new(0); 831 do { 832 sh_string_read(s, task.pipe, 0); 833 if (sh_string_len(s) == 0) 834 { 835 --try; retry_msleep(0, 100); 836 } 837 } while (sh_string_len(s) == 0 && try != 0); 838 839 if (sh_string_len(s) == 0) 840 { 841 sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, status, MSG_E_SUBGEN, 842 _("No output from command"), _("sh_ext_popen_str")); 843 } 844 845 out = sh_util_strdup(sh_string_str(s)); 846 sh_string_destroy(&s); 847 } 848 849 /* restore old signal handler 850 */ 851 (void) retry_sigaction (FIL__, __LINE__, SIGPIPE, &old_act, NULL); 852 853 /* close pipe and return exit status 854 */ 855 (void) sh_ext_pclose(&task); 856 sh_ext_tas_free (&task); 857 SL_RETURN ((out), _("sh_ext_popen_str")); 858 } 859 860 861 775 862 776 863 /* --------------- EXTERN STUFF ------------------- */ … … 1141 1228 (void) sh_ext_add_envv (_("HOME"), p); 1142 1229 (void) sh_ext_add_envv (_("SHELL"), _("/bin/sh")); 1143 (void) sh_ext_add_envv (_("PATH"), _("/sbin:/usr/sbin:/bin:/usr/bin")); 1230 (void) sh_ext_add_envv (_("PATH"), _("/sbin:/bin:/usr/sbin:/usr/bin")); 1231 (void) sh_ext_add_envv (_("IFS"), " \n\t"); 1144 1232 i = (p == NULL ? (-1) : 0); 1145 1233 SL_RETURN(i, _("sh_ext_add_default"));
Note:
See TracChangeset
for help on using the changeset viewer.