| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

process_setinfo

#include "sflproc.h"
int
process_setinfo (
    PROCESS_DATA *procinfo,
    const char *std_in,                 /*  Stdin device, or NULL            */
    const char *std_out,                /*  Stdout device, or NULL           */
    Bool  scratch_out,                  /*  Scratch stdout file?             */
    const char *std_err,                /*  Stderr device, or NULL           */
    Bool  scratch_err                   /*  Scratch stderr file?             */
)

Synopsis

Accepts a pointer to a PROC_INFO block, and resets the fields in this block to default values as specified below (other fields are not changed):
searchpath True unless filename already contains a slash
in Std_in filename, or NULL
out Std_out filename, or NULL
err Std_err filename, or NULL
preserveroot True if we're running as root now
Returns 0 if the PROC_INFO block was correctly initialised; returns -1 if there was an error opening one of the i/o streams. Before calling this function you should have declared the PROC_INFO block using the syntax: PROCESS_DATA myproc = PROCESS_DATA_INIT;

Source Code - (sflproc.c)

{
    const char
        *spacepos,
        *slashpos;
    char
        stdout_mode,
        stderr_mode;

    /*  Figure out if it is permissable to search the path                   */
    /*  It's permissable if the filename to be run doesn't contain a slash   */
    /*  of its own already.                                                  */
    procinfo-> searchpath = FALSE;
    if (procinfo-> filename)
      {
        spacepos = strchr (procinfo-> filename, ' ');
        if (spacepos == NULL)
            spacepos = procinfo-> filename + strlen (procinfo-> filename);
        slashpos = strchr (procinfo-> filename, '/');
#if (defined (MSDOS_FILESYSTEM))
        if (!slashpos)
            slashpos = strchr (procinfo-> filename, '\\');
#endif
        if (slashpos == NULL || slashpos > spacepos)
            procinfo-> searchpath = TRUE;
      }
    /*  Figure out if root privilege should be retained.  If the real user   */
    /*  is root and effective user is root, then we retain root privilege    */
    /*  for the executed program.  Otherwise we want to discard it (default) */
    procinfo-> preserveroot = FALSE;
#if (defined (__UNIX__))
    if (getuid () == 0 && geteuid () == 0)
        procinfo-> preserveroot = TRUE;
#endif

    /*  Open the i/o streams if requested.  Note that process_set_io
     *  returns NULL_HANDLE if the supplied filename is null or empty.
     */
    stdout_mode = scratch_out? 'w': 'a';
    stderr_mode = scratch_err? 'w': 'a';
    procinfo-> in  = process open io (std_in,  'r');
    procinfo-> out = process open io (std_out, stdout_mode);
    procinfo-> err = process open io (std_err, stderr_mode);
    if (procinfo-> in  == -1
    ||  procinfo-> out == -1
    ||  procinfo-> err == -1)
      {
        process close io (procinfo);
        return (-1);
      }
    else
        return (0);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation