Patch: status/start/stop return value

Johan Kiviniemi netsplit.com-upstart-devel at johan.kiviniemi.name
Mon Sep 4 14:43:51 BST 2006


With this patch, status returns 1 if *any* of the queried jobs is *not
running*.  That makes it possible to do something like this in a script:

if status job0 job1 >/dev/null 2>&1; then
	# both jobs are running, do stuff
fi

start and stop also return 1 if a job is unknown or an unexpected reply
is received.

(Perhaps there should be a -q/--quiet parameter for status?)

-- 
Jοhan Kiviniemi  http://johan.kiviniemi.name/
-------------- next part --------------
=== modified file 'util/start.c'
--- util/start.c	2006-08-31 01:58:45 +0000
+++ util/start.c	2006-09-04 13:38:39 +0000
@@ -62,6 +62,7 @@
 {
 	char **args, **arg;
 	int    mode, sock;
+	int    ret = 0;
 
 	nih_main_init (argv[0]);
 
@@ -154,18 +155,25 @@
 					reply->job_status.pid,
 					process_state_name (reply->job_status.process_state));
 			}
+
+			if ((mode == STATUS)
+			    && (reply->job_status.state != JOB_RUNNING))
+				ret = 1;
+
 			break;
 		case UPSTART_JOB_UNKNOWN:
 			fprintf (stderr, _("%s: Unknown job: %s\n"),
 				 program_name, reply->job_unknown.name);
+			ret = 1;
 			break;
 		default:
 			fprintf (stderr, _("%s: Unexpected reply (type %d)\n"),
 				 program_name, reply->type);
+			ret = 1;
 		}
 
 		nih_free (reply);
 	}
 
-	return 0;
+	return ret;
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/upstart-devel/attachments/20060904/cc50f8b2/attachment.pgp 


More information about the Upstart-devel mailing list