Skip to content

Commit

Permalink
Add -r option to provide return code
Browse files Browse the repository at this point in the history
  • Loading branch information
abligh committed Sep 22, 2015
1 parent 37f97dd commit 51a21a7
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions main.c
@@ -1,10 +1,12 @@
#include "apue.h"
#include <termios.h>
#include <sys/types.h>
#include <sys/wait.h>

#ifdef LINUX
#define OPTSTR "+d:einv"
#define OPTSTR "+d:einvr"
#else
#define OPTSTR "d:einv"
#define OPTSTR "d:einvr"
#endif

static void set_noecho (int); /* at the end of this file */
Expand All @@ -14,7 +16,7 @@ void loop (int, int); /* in the file loop.c */
int
main (int argc, char *argv[])
{
int fdm, c, ignoreeof, interactive, noecho, verbose;
int fdm, c, ignoreeof, interactive, noecho, verbose, returncode, status;
pid_t pid;
char *driver;
char slave_name[20];
Expand All @@ -26,6 +28,7 @@ main (int argc, char *argv[])
noecho = 0;
verbose = 0;
driver = NULL;
returncode = 0;

opterr = 0; /* don't want getopt() writing to stderr */
while ((c = getopt (argc, argv, OPTSTR)) != EOF)
Expand All @@ -52,6 +55,10 @@ main (int argc, char *argv[])
verbose = 1;
break;

case 'r':
returncode = 1;
break;

case '?':
err_quit ("unrecognized option: -%c", optopt);
}
Expand Down Expand Up @@ -106,6 +113,17 @@ main (int argc, char *argv[])

loop (fdm, ignoreeof); /* copies stdin -> ptym, ptym -> stdout */

if (returncode)
{
if (waitpid (pid, &status, 0) < 0)
err_sys ("waitpid error");
if (WIFEXITED (status))
exit (WEXITSTATUS (status));
else
exit (EXIT_FAILURE);
}


exit (0);
}

Expand Down

0 comments on commit 51a21a7

Please sign in to comment.