view sciworkerd/main.c @ 22:dd078aea5d02

misc: use project/worker name as primary key
author David Demelier <markand@malikania.fr>
date Thu, 21 Jul 2022 20:23:22 +0200
parents de4bf839b565
children 2cb228f23f53
line wrap: on
line source

/*
 * sciworkerd.c -- main sciworkerd(8) program file
 *
 * Copyright (c) 2021 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "sciworkerd.h"

static void
env(void)
{
	const char *env;

	if ((env = getenv("SCI_URL")))
		snprintf(sciworkerd.url, sizeof (sciworkerd.url), "%s", optarg);
	if ((env = getenv("SCI_WORKER")))
		snprintf(sciworkerd.name, sizeof (sciworkerd.name), "%s", optarg);
}

int
main(int argc, char **argv)
{
	int ch, val;

	env();
	opterr = 0;

	while ((ch = getopt(argc, argv, "j:t:u:w:")) != -1) {
		switch (ch) {
		case 'j':
			if ((val = atoi(optarg)) > 0)
				sciworkerd.maxjobs = val;
			break;
		case 't':
			if ((val = atoi(optarg)) > 0)
				sciworkerd.timeout = val;
			break;
		case 'u':
			snprintf(sciworkerd.url, sizeof (sciworkerd.url), "%s", optarg);
			break;
		case 'w':
			snprintf(sciworkerd.name, sizeof (sciworkerd.name), "%s", optarg);
			break;
		default:
			break;
		}
	}
}