Skip to content

Commit

Permalink
solaris: Use getopt_long() to print version
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Jan 5, 2025
1 parent bb04e92 commit cd273e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 0 additions & 1 deletion bsd/restartable.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ version(void) {
int
main(int argc, char *argv[]) {
int ch;

struct option longopts[] = {
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
Expand Down
24 changes: 20 additions & 4 deletions solaris/restartable.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <libproc.h>
#define _KERNEL
#include <sys/procfs.h>

#define VERSION "2.3.4"

static int verbose;

static int
Expand Down Expand Up @@ -146,31 +149,44 @@ print_all(void) {
}

static void
usage(void)
{
usage(void) {
fprintf(stderr, "Usage: %s [-v]\n", getprogname());
exit(1);
}

static void
version(void) {
printf("%s %s\n", getprogname(), VERSION);
}

int
main(int argc, char *argv[]) {
int ch;
struct option longopts[] = {
{"verbose", no_argument, NULL, 'v'},
{"version", no_argument, NULL, 'V'},
};

while ((ch = getopt(argc, argv, "v")) != -1) {
while ((ch = getopt_long(argc, argv, "v", longopts, NULL)) != -1) {
switch (ch) {
case 'v':
verbose = 1;
break;
case 'V':
version();
return (0);
default:
usage();
}
}

argc -= optind;
argv += optind;
if (argc != 0)
usage();

printf("PID\tPPID\tUID\tUser\tCommand\n");
print_all();

return 0;
return (0);
}

0 comments on commit cd273e2

Please sign in to comment.