c - Launch a program using sudo -
i want launch program using sudo, have used command
sudo './connectionmanager'
on a:
distributor id: scientificsl description: scientific linux sl release 5.5 (boron) release: 5.5 codename: boron (like centos5.5)
and works, doesn't work on
distributor id: scientific description: scientific linux release 6.4 (carbon) release: 6.4 codename: carbon
in last case have following message: [1]+ stopped sudo './connectionmanager'
i have check code , problem instruction int setpgrp(void)
in connectionmanager.
connectionmanager program written in c, wich fork process in order wait tcp/ip connnection.
someone can me ?
follow sample code
#include <stdio.h> #include <ncurses.h> ... int main() { if (chdir("/opt/informix/server") == -1) { printf("errore nella directory /opt/informix/server\n"); getch(); exit(1); }; signal(sigint, onexit); signal(sigusr1, refreshmainwindow); signal(sigpipe, sig_ign); signal(sigcld, sig_ign); setpgrp(); parentpid = getpid(); /***/ if (lockfile(_true) != _ok) { exit(1); } if (createdestroyshm(_true) != _ok) { exit(1); } ... if (lockfile(_false, &sdebug) != _ok) { exit(1); } /***/ init_curses(); menubar = subwin(stdscr, 1, maxcols, 0, 0); main_win = subwin(stdscr, maxrows-1, maxcols, 1, 0); cbreak(); /* acquire each keystroke */ printtestata(); draw_menubar(menubar); /***/ switch (fork()) { case 0: signal(sigusr1, sig_ign); break; default: keyboardhandler(); } void init_curses() { putenv("term=xterm"); initscr(); wresize(stdscr, maxrows, maxcols); start_color(); init_pair(1,color_white,color_red); init_pair(2,color_blue,color_white); init_pair(3, color_green, color_blue); init_pair(4, color_red, color_blue); curs_set(0); noecho(); keypad(stdscr,true); touchwin(stdscr); wrefresh(stdscr); }
perhaps process not in sessions foreground process group , despite tries read or write terminal.
see "notes" section in http://man7.org/linux/man-pages/man2/setpgid.2.html , "jobs , sessions" http://www.linusakesson.net/programming/tty/.
you check in code if (tcgetpgrp(stdout_fileno) == getpgid(0))
. if not, not in foreground.
Comments
Post a Comment