void writePiFaceCAD(const char * displayString, unsigned short channel) { char * cp; char buf[101]; if (channel == 0) { #ifdef RASPBERRYPI pifacecad_lcd_clear(); pifacecad_lcd_write(displayString); /* write direct to PiFaceCAD */ #else /* RASPBERRYPI */ fprintf(stderr, "ERROR: cannot write directly to PiFaceCAD\n"); iC_quit(SIGUSR1); #endif /* RASPBERRYPI */ } else if (channel < 0xfff0) { cp = buf; if (snprintf(buf, 100, "%hu:%s", channel, displayString) > 100) { buf[100] = '\0'; /* terminate in case of overflow (unlikely) */ } #if YYDEBUG if (iC_debug & 0200) { fprintf(iC_outFP, "writePiFaceCAD: '%s'\n", buf); /* terminate with a CR in case last line has none */ } #endif /* YYDEBUG */ while ((cp = strchr(cp+1 , ',')) != NULL) { /* no commas in channel: */ *cp = '\036'; /* replace every comma by ASCII RS */ } assert(iC_sockFN > 0); iC_send_msg_to_server(iC_sockFN, buf); } else { fprintf(stderr, "ERROR: unable to register as PFCAD4 sender - is PiFaceCAD input correct ?\n"); iC_quit(SIGUSR1); } } /* writePiFaceCAD */
void iC_err_fn( /* error - no master or slave function */ Gate * gp, Gate * out_list) { #if !defined(_WINDOWS) || defined(LOAD) fprintf(iC_errFP, "\n%s: line %d: Gate %s, action %d not implemented", __FILE__, __LINE__, gp->gt_ids, gp->gt_fni); iC_quit(-1); #endif /* !defined(_WINDOWS) || defined(LOAD) */ } /* err_fn */
void iC_fork_and_exec(char ** argv) { pid_t pid; uid_t uid; uid_t euid; char * cp; char ** cpp = argv; #ifdef TCP char ** epp; int extraArgs = 0; char * hostp = NULL; char * portp = NULL; if (strcmp(iC_hostNM, LOCALHOST) && strcmp(iC_hostNM, LOCALHOST1)) { extraArgs += 2; hostp = (char *)iC_hostNM; } if (strcmp(iC_portNM, iC_PORT)) { extraArgs += 2; portp = (char *)iC_portNM; } if (extraArgs) { assert(*cpp); /* must have at least one argument - the program to execute */ while (*cpp++) { extraArgs++; /* add original number of arguments */ } epp = cpp = (char **)iC_emalloc((extraArgs + 1) * sizeof(char*)); extraArgs--; /* count arguments for final assertion check */ *epp++ = *argv++; /* copy pointer to program first */ if (hostp) { extraArgs -= 2; *epp++ = "-s"; *epp++ = hostp; /* followed by optional -s hostp */ } if (portp) { extraArgs -= 2; *epp++ = "-p"; *epp++ = portp; /* followed by optional -s portp */ } while ((cp = *argv++) != NULL) { extraArgs--; *epp++ = cp; /* copy rest of original argument pointers */ } assert(extraArgs == 0); /* final assertion check */ *epp = NULL; /* argv terminator in extra element allowed for in malloc */ argv = cpp; /* new extended arguments */ } #endif /* TCP */ uid = getuid(); euid = geteuid(); if (iC_debug & 04) fprintf(iC_errFP, "uid = %d euid = %d\n", (int)uid, (int)euid); /******************************************************************** * Display the call + arguments to keep track of what is happening * unless -q quiet operation * $ call arg1 arg2 ... argn *******************************************************************/ if ((iC_debug & DQ) == 0) { fprintf(iC_errFP, "$"); while ((cp = *cpp++) != NULL) { fprintf(iC_errFP, " %s", cp); } fprintf(iC_errFP, " &\n"); } /******************************************************************** * Fork now *******************************************************************/ if ((pid = fork()) == 0) { /* child process */ if (euid != uid) { if (seteuid(uid) != 0) { /* execute child process at uid privileges */ perror("seteuid failed"); /* hard ERROR */ exit(SIGUSR1); } } execvp(*argv, argv); /* execute call in parallel child process */ /* only get here if exec fails */ fprintf(iC_errFP, "Could not execute %s - ", *argv); perror(""); /* hard ERROR */ exit(SIGUSR1); /* do not use iC_quit to avoid termQuit() for parent stuff */ } else if (pid < 0) { perror("fork failed"); /* hard ERROR */ iC_quit(SIGUSR1); /* still parent */ } /* continue parent process with extended privileges */ } /* iC_fork_and_exec */