Example #1
0
int main(int argc, char * argv[])
{
	putenv("LANG=");
	do_all(argc, argv);
	/* Return on error */
	perror(argv[0]);
	exit(1);
	return 1;
}
Example #2
0
void
dserv_daemon(dserv_handle_t *handle)
{
	struct svcpool_args dserv_svcpool;
	struct protob dservproto;

	bzero(&dserv_svcpool, sizeof (dserv_svcpool));

	dserv_svcpool.id = UNIQUE_SVCPOOL_ID;

	if (_nfssys(SVCPOOL_CREATE, &dserv_svcpool)) {
		dserv_log(handle, LOG_ERR,
		    gettext("SVCPOOL_CREATE failed: %m"));
		exit(1);
	}

	dserv_set_pool_id(handle, dserv_svcpool.id);

	if (svcwait(dserv_svcpool.id)) {
		dserv_log(handle, LOG_ERR,
		    gettext("svcwait(DSERV_SVCPOOL_ID) failed: %m"));
		exit(1);
	}

	dservproto.serv = "DSERV";
	dservproto.versmin = PNFSCTLMDS_V1;
	dservproto.versmax = PNFSCTLMDS_V1;
	dservproto.program = PNFSCTLMDS;
	dservproto.flags = PROTOB_NO_REGISTER;
	dservproto.next = NULL;

	/*
	 * We love globals!
	 */
	Mysvc4 = dserv_service;
	do_all_handle = handle;
	if (do_all(&dservproto, NULL, 0) == -1) {
		dserv_log(handle, LOG_ERR,
		    gettext("do_all(): %m"));
		exit(1);
	}
	if (num_fds == 0) {
		dserv_log(handle, LOG_ERR,
		    gettext("Could not start DSERV service for any protocol"));
		exit(1);
	}

	end_listen_fds = num_fds;
	poll_for_action();

	dserv_log(handle, LOG_INFO,
	    gettext("I am shutting down now"));

	exit(1);
}
Example #3
0
int main(int argc, char** argv, char** envp) {
	char *display=NULL;
	unsigned long vmask;
	XSetWindowAttributes xswat;
	XGCValues gcvals;
	Bool use_planes=False;
	int i;

	srandom(getpid());
	for (i=1; i < argc; i++) {
		if (strncmp(argv[i], "-dis", 4) == 0) {
			if (argv[i+1])
				display=argv[++i];
			else
				usage();
		} else if (strncmp(argv[i], "-p", 2) == 0) {
			use_planes=1;
		} else
			usage();
	}
	if ((dpy=XOpenDisplay(display)) == NULL) {
		fprintf(stderr, "can't open display\n");
		exit(0);
	}
	screen=DefaultScreen(dpy);

	xswat.override_redirect=True;
	xswat.do_not_propagate_mask=KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask;
	vmask=CWOverrideRedirect|CWDontPropagate;
	win=XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0,
		DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
		0, CopyFromParent, CopyFromParent, CopyFromParent, vmask,
		&xswat);
	XMapWindow(dpy, win);

	gcvals.graphics_exposures=False;
	/* copyplane gc wants to leave the data alone */
	gcvals.foreground=1;
	gcvals.background=0;
	copygc=XCreateGC(dpy, win,
		GCForeground|GCBackground|GCGraphicsExposures, &gcvals);

	gcvals.foreground=BlackPixel(dpy, screen);
	fillgc=XCreateGC(dpy, win, GCForeground, &gcvals);

	XSync(dpy, 0);
	if (use_planes) {
		do_planes();
	} else {
		do_all();
	}
	sleep(2);
	return EXIT_SUCCESS;
}
Example #4
0
FrameIterator::FrameIterator( frame* _f, RegisterLocator* _rl, bool z, RegisterString m, bool r, OopClosure* c ) {
  f = _f; rl = _rl;  zap = z;  mask = m;  reinit = r;  oop_closure = c;
  do_all();
}
Example #5
0
void edit_level(void) {
    int ch = 0;
    int kohta = 0;
    int c;
    int x, y, n1, n2;
    int current = -1;
    int active = -1;
    int airfield_set = -1;
    unsigned char colori = 0;
    FILE *faili;

    Bitmap *pointti;
    pointti = new Bitmap(1, 1, &colori);

    while (!(ch == SDLK_ESCAPE)) {
        colori++;
        pb_picture->blit(-kohta, 0);
        for (c = 0; c < MAX_STRUCTURES; c++) {
            if (leveldata.struct_x[c]) {
                struct_picture[c]->blit(leveldata.struct_x[c] - kohta, leveldata.struct_y[c]);
            }
        }

        if (active != -1) {
            if (leveldata.struct_x[active] >= kohta && leveldata.struct_x[active] <= (kohta + 300))

                boxi(leveldata.struct_x[active] - kohta,
                     leveldata.struct_y[active],
                     leveldata.struct_x[active] - kohta + picture_width[active], leveldata.struct_y[active] + picture_height[active], 1);
        }

        for (c = 0; c < 4; c++)
            if (leveldata.airfield_x[c])
                omaline(leveldata.airfield_x[c] - kohta, leveldata.airfield_y[c],
                        leveldata.airfield_x[c] - kohta + leveldata.airfield_lenght[c], leveldata.airfield_y[c], colori);


        if (active != -1) {
            lappu1->blit(220, 0);
            fontti->printf(235, 4, "%s", leveldata.pd_name[active]);
            fontti->printf(235, 14, "X:%d Y:%d", leveldata.struct_x[active], leveldata.struct_y[active]);
            fontti->printf(235, 23, "%s", owner_names[leveldata.struct_owner[active]]);
            fontti->printf(235, 32, "%s", hitting_names[leveldata.struct_hit[active]]);
            fontti->printf(235, 41, "%s", type_names[leveldata.struct_type[active]]);
        }

        lappu2->blit(262, 184);
        fontti->printf(265, 188, "%s", leveldata.pb_name);

        koords(&x, &y, &n1, &n2);
        hiirikursori->blit(x, y);

        if (airfield_set != -1 && (n1 || n2)) {
            hiirikursori = hiirik;
            leveldata.airfield_x[airfield_set] = x + kohta;
            leveldata.airfield_y[airfield_set] = y;
            if (n1)
                leveldata.plane_direction[airfield_set] = 0;
            else
                leveldata.plane_direction[airfield_set] = 1;
            airfield_set = -1;
        }

        if (n1 && (current != -1)) {
            leveldata.struct_x[current] = x + kohta;
            leveldata.struct_y[current] = y;
            hiirikursori = hiirik;
            current = -1;
        } else if (n1 && (active == -1)) {
            for (c = 0; c < MAX_STRUCTURES; c++) {
                if ((x + kohta) >= leveldata.struct_x[c] &&
                    (x + kohta) <= (leveldata.struct_x[c] + picture_width[c]) && y >= leveldata.struct_y[c] && y <= (leveldata.struct_y[c] + picture_height[c]))
                    break;

            }

            if (c != MAX_STRUCTURES) {
                active = c;

            }
        }


        if (n2 && (active != -1)) {
            active = -1;
        }

        do_all();
        //while(!kbhit());

        if (kbhit()) {
            ch = getch();

            switch (ch) {
            case SDLK_F2:
                swap_byte_order();
                faili = fopen(filename, "wb");
                fwrite(&leveldata, sizeof(leveldata), 1, faili);
                fclose(faili);
                swap_byte_order();
                break;

            case SDLK_INSERT:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                fontti->printf(10, 10, "StructureNAME");
                fontti->scanf(10, 20, leveldata.pd_name[c], 6);
                if (!leveldata.pd_name[c][0])
                    break;
                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F5:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;

                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 0;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F6:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 1;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F7:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 2;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;

            case SDLK_F8:
                if (active != -1)
                    break;

                for (c = 0; c < MAX_STRUCTURES; c++)
                    if (!leveldata.struct_x[c])
                        break;
                if (c == MAX_STRUCTURES)
                    break;

                strcpy(leveldata.pd_name[c], "INFAN");

                if (!bitmap_exists(leveldata.pd_name[c]))
                    break;

                leveldata.struct_owner[c] = 3;
                leveldata.struct_type[c] = 0;
                struct_picture[c] = new Bitmap(leveldata.pd_name[c]);
                hiirikursori = struct_picture[c];
                hiirikursori->info(&picture_width[c], &picture_height[c]);
                current = c;
                break;


            case SDLK_DELETE:
                if (active != -1) {
                    leveldata.struct_x[active] = 0;
                    delete struct_picture[active];
                    active = -1;

                }
                break;

            case SDLK_HOME:
                if (active != -1) {
                    leveldata.struct_owner[active]++;
                    if (leveldata.struct_owner[active] >= 5)
                        leveldata.struct_owner[active] = 0;

                }
                break;

            case SDLK_END:
                if (active != -1) {
                    leveldata.struct_hit[active]++;
                    if (leveldata.struct_hit[active] >= 2)
                        leveldata.struct_hit[active] = 0;
                }
                break;
            case SDLK_RIGHT:
                kohta += 106;
                if (kohta > 2080)
                    kohta = 2080;
                break;

            case SDLK_LEFT:
                kohta -= 106;
                if (kohta < 0)
                    kohta = 0;
                break;

            case SDLK_PAGEUP:
                char temp_stringi[10];
                temp_stringi[0] = 0;
                fontti->scanf(265, 178, temp_stringi, 6);

                if (!bitmap_exists(temp_stringi))
                    break;


                strcpy(leveldata.pb_name, temp_stringi);
                delete pb_picture;
                pb_picture = new Bitmap(temp_stringi);
                break;

            case SDLK_PAGEDOWN:
                if (active != -1) {
                    leveldata.struct_type[active]++;
                    if (leveldata.struct_type[active] >= MAX_TYPES)
                        leveldata.struct_type[active] = 0;
                }
                break;
            case SDLK_q:
                leveldata.airfield_lenght[0]++;
                if (leveldata.airfield_lenght[0] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[0] = MAX_AIRFIELD_LENGHT;
                break;
            case SDLK_w:
                leveldata.airfield_lenght[1]++;
                if (leveldata.airfield_lenght[1] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[1] = MAX_AIRFIELD_LENGHT;
                break;
            case SDLK_e:
                leveldata.airfield_lenght[2]++;
                if (leveldata.airfield_lenght[2] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[2] = MAX_AIRFIELD_LENGHT;
                break;
            case SDLK_r:
                leveldata.airfield_lenght[3]++;
                if (leveldata.airfield_lenght[3] > MAX_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[3] = MAX_AIRFIELD_LENGHT;
                break;

            case SDLK_a:
                leveldata.airfield_lenght[0]--;
                if (leveldata.airfield_lenght[0] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[0] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_s:
                leveldata.airfield_lenght[1]--;
                if (leveldata.airfield_lenght[1] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[1] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_d:
                leveldata.airfield_lenght[2]--;
                if (leveldata.airfield_lenght[2] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[2] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_f:
                leveldata.airfield_lenght[3]--;
                if (leveldata.airfield_lenght[3] < MIN_AIRFIELD_LENGHT)
                    leveldata.airfield_lenght[3] = MIN_AIRFIELD_LENGHT;
                break;

            case SDLK_PLUS:
                if (active == -1 || active == 99)
                    break;

                if (leveldata.struct_x[active + 1]);
                active++;
                break;

            case SDLK_MINUS:
                if (active < 1)
                    break;

                if (leveldata.struct_x[active - 1]);
                active--;
                break;
            default:
                if ((ch >= SDLK_1) && (ch <= SDLK_4)) {
                    airfield_set = ch - SDLK_1;
                    hiirikursori = pointti;
                }
                break;
            }
        }
    }

    delete pointti;

}
Example #6
0
int
main(int ac, char *av[])
{
	char *dir = "/";
	int allflag = 0;
	int df_allflag = 0;
	int opt_cnt = 0;
	int maxservers = 1;	/* zero allows inifinte number of threads */
	int maxservers_set = 0;
	int logmaxservers = 0;
	int pid;
	int i;
	char *provider = (char *)NULL;
	char *df_provider = (char *)NULL;
	struct protob *protobp0, *protobp;
	NETSELDECL(proto) = NULL;
	NETSELDECL(df_proto) = NULL;
	NETSELPDECL(providerp);
	char *defval;
	boolean_t can_do_mlp;
	uint_t dss_npaths = 0;
	char **dss_pathnames = NULL;
	sigset_t sgset;
	char name[PATH_MAX], value[PATH_MAX];
	int ret, bufsz;

	int pipe_fd = -1;

	MyName = *av;

	/*
	 * Initializations that require more privileges than we need to run.
	 */
	(void) _create_daemon_lock(NFSD, DAEMON_UID, DAEMON_GID);
	svcsetprio();

	can_do_mlp = priv_ineffect(PRIV_NET_BINDMLP);
	if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET,
	    DAEMON_UID, DAEMON_GID, PRIV_SYS_NFS,
	    can_do_mlp ? PRIV_NET_BINDMLP : NULL, NULL) == -1) {
		(void) fprintf(stderr, "%s should be run with"
		    " sufficient privileges\n", av[0]);
		exit(1);
	}

	(void) enable_extended_FILE_stdio(-1, -1);

	/*
	 * Read in the values from SMF first before we check
	 * command line options so the options override SMF values.
	 */
	bufsz = PATH_MAX;
	ret = nfs_smf_get_prop("max_connections", value, DEFAULT_INSTANCE,
	    SCF_TYPE_INTEGER, NFSD, &bufsz);
	if (ret == SA_OK) {
		errno = 0;
		max_conns_allowed = strtol(value, (char **)NULL, 10);
		if (errno != 0)
			max_conns_allowed = -1;
	}

	bufsz = PATH_MAX;
	ret = nfs_smf_get_prop("listen_backlog", value, DEFAULT_INSTANCE,
	    SCF_TYPE_INTEGER, NFSD, &bufsz);
	if (ret == SA_OK) {
		errno = 0;
		listen_backlog = strtol(value, (char **)NULL, 10);
		if (errno != 0) {
			listen_backlog = 32;
		}
	}

	bufsz = PATH_MAX;
	ret = nfs_smf_get_prop("protocol", value, DEFAULT_INSTANCE,
	    SCF_TYPE_ASTRING, NFSD, &bufsz);
	if ((ret == SA_OK) && strlen(value) > 0) {
		df_proto = strdup(value);
		opt_cnt++;
		if (strncasecmp("ALL", value, 3) == 0) {
			free(df_proto);
			df_proto = NULL;
			df_allflag = 1;
		}
	}

	bufsz = PATH_MAX;
	ret = nfs_smf_get_prop("device", value, DEFAULT_INSTANCE,
	    SCF_TYPE_ASTRING, NFSD, &bufsz);
	if ((ret == SA_OK) && strlen(value) > 0) {
		df_provider = strdup(value);
		opt_cnt++;
	}

	bufsz = PATH_MAX;
	ret = nfs_smf_get_prop("servers", value, DEFAULT_INSTANCE,
	    SCF_TYPE_INTEGER, NFSD, &bufsz);
	if (ret == SA_OK) {
		errno = 0;
		maxservers = strtol(value, (char **)NULL, 10);
		if (errno != 0)
			maxservers = 1;
		else
			maxservers_set = 1;
	}

	bufsz = 4;
	ret = nfs_smf_get_prop("server_versmin", value, DEFAULT_INSTANCE,
	    SCF_TYPE_INTEGER, NFSD, &bufsz);
	if (ret == SA_OK)
		nfs_server_vers_min = strtol(value, (char **)NULL, 10);

	bufsz = 4;
	ret = nfs_smf_get_prop("server_versmax", value, DEFAULT_INSTANCE,
	    SCF_TYPE_INTEGER, NFSD, &bufsz);
	if (ret == SA_OK)
		nfs_server_vers_max = strtol(value, (char **)NULL, 10);

	bufsz = PATH_MAX;
	ret = nfs_smf_get_prop("server_delegation", value, DEFAULT_INSTANCE,
	    SCF_TYPE_ASTRING, NFSD, &bufsz);
	if (ret == SA_OK)
		if (strncasecmp(value, "off", 3) == 0)
			nfs_server_delegation = FALSE;

	/*
	 * Conflict options error messages.
	 */
	if (opt_cnt > 1) {
		(void) fprintf(stderr, "\nConflicting options, only one of "
		    "the following options can be specified\n"
		    "in SMF:\n"
		    "\tprotocol=ALL\n"
		    "\tprotocol=protocol\n"
		    "\tdevice=devicename\n\n");
		usage();
	}
	opt_cnt = 0;

	while ((i = getopt(ac, av, "ac:p:s:t:l:")) != EOF) {
		switch (i) {
		case 'a':
			free(df_proto);
			df_proto = NULL;
			free(df_provider);
			df_provider = NULL;

			allflag = 1;
			opt_cnt++;
			break;

		case 'c':
			max_conns_allowed = atoi(optarg);
			break;

		case 'p':
			proto = optarg;
			df_allflag = 0;
			opt_cnt++;
			break;

		/*
		 * DSS: NFSv4 distributed stable storage.
		 *
		 * This is a Contracted Project Private interface, for
		 * the sole use of Sun Cluster HA-NFS. See PSARC/2006/313.
		 */
		case 's':
			if (strlen(optarg) < MAXPATHLEN) {
				/* first "-s" option encountered? */
				if (dss_pathnames == NULL) {
					/*
					 * Allocate maximum possible space
					 * required given cmdline arg count;
					 * "-s <path>" consumes two args.
					 */
					size_t sz = (ac / 2) * sizeof (char *);
					dss_pathnames = (char **)malloc(sz);
					if (dss_pathnames == NULL) {
						(void) fprintf(stderr, "%s: "
						    "dss paths malloc failed\n",
						    av[0]);
						exit(1);
					}
					(void) memset(dss_pathnames, 0, sz);
				}
				dss_pathnames[dss_npaths] = optarg;
				dss_npaths++;
			} else {
				(void) fprintf(stderr,
				    "%s: -s pathname too long.\n", av[0]);
			}
			break;

		case 't':
			provider = optarg;
			df_allflag = 0;
			opt_cnt++;
			break;

		case 'l':
			listen_backlog = atoi(optarg);
			break;

		case '?':
			usage();
			/* NOTREACHED */
		}
	}

	allflag = df_allflag;
	if (proto == NULL)
		proto = df_proto;
	if (provider == NULL)
		provider = df_provider;

	/*
	 * Conflict options error messages.
	 */
	if (opt_cnt > 1) {
		(void) fprintf(stderr, "\nConflicting options, only one of "
		    "the following options can be specified\n"
		    "on the command line:\n"
		    "\t-a\n"
		    "\t-p protocol\n"
		    "\t-t transport\n\n");
		usage();
	}

	if (proto != NULL &&
	    strncasecmp(proto, NC_UDP, strlen(NC_UDP)) == 0) {
		if (nfs_server_vers_max == NFS_V4) {
			if (nfs_server_vers_min == NFS_V4) {
				fprintf(stderr,
				    "NFS version 4 is not supported "
				    "with the UDP protocol.  Exiting\n");
				exit(3);
			} else {
				fprintf(stderr,
				    "NFS version 4 is not supported "
				    "with the UDP protocol.\n");
			}
		}
	}

	/*
	 * If there is exactly one more argument, it is the number of
	 * servers.
	 */
	if (optind == ac - 1) {
		maxservers = atoi(av[optind]);
		maxservers_set = 1;
	}
	/*
	 * If there are two or more arguments, then this is a usage error.
	 */
	else if (optind < ac - 1)
		usage();
	/*
	 * Check the ranges for min/max version specified
	 */
	else if ((nfs_server_vers_min > nfs_server_vers_max) ||
	    (nfs_server_vers_min < NFS_VERSMIN) ||
	    (nfs_server_vers_max > NFS_VERSMAX))
		usage();
	/*
	 * There are no additional arguments, and we haven't set maxservers
	 * explicitly via the config file, we use a default number of
	 * servers.  We will log this.
	 */
	else if (maxservers_set == 0)
		logmaxservers = 1;

	/*
	 * Basic Sanity checks on options
	 *
	 * max_conns_allowed must be positive, except for the special
	 * value of -1 which is used internally to mean unlimited, -1 isn't
	 * documented but we allow it anyway.
	 *
	 * maxservers must be positive
	 * listen_backlog must be positive or zero
	 */
	if (((max_conns_allowed != -1) && (max_conns_allowed <= 0)) ||
	    (listen_backlog < 0) || (maxservers <= 0)) {
		usage();
	}

	/*
	 * Set current dir to server root
	 */
	if (chdir(dir) < 0) {
		(void) fprintf(stderr, "%s:  ", MyName);
		perror(dir);
		exit(1);
	}

#ifndef DEBUG
	pipe_fd = daemonize_init();
#endif

	openlog(MyName, LOG_PID | LOG_NDELAY, LOG_DAEMON);

	/*
	 * establish our lock on the lock file and write our pid to it.
	 * exit if some other process holds the lock, or if there's any
	 * error in writing/locking the file.
	 */
	pid = _enter_daemon_lock(NFSD);
	switch (pid) {
	case 0:
		break;
	case -1:
		fprintf(stderr, "error locking for %s: %s\n", NFSD,
		    strerror(errno));
		exit(2);
	default:
		/* daemon was already running */
		exit(0);
	}

	/*
	 * If we've been given a list of paths to be used for distributed
	 * stable storage, and provided we're going to run a version
	 * that supports it, setup the DSS paths.
	 */
	if (dss_pathnames != NULL && nfs_server_vers_max >= DSS_VERSMIN) {
		if (dss_init(dss_npaths, dss_pathnames) != 0) {
			fprintf(stderr, "%s", "dss_init failed. Exiting.\n");
			exit(1);
		}
	}

	/*
	 * Block all signals till we spawn other
	 * threads.
	 */
	(void) sigfillset(&sgset);
	(void) thr_sigsetmask(SIG_BLOCK, &sgset, NULL);

	if (logmaxservers) {
		fprintf(stderr,
		    "Number of servers not specified. Using default of %d.\n",
		    maxservers);
	}

	/*
	 * Make sure to unregister any previous versions in case the
	 * user is reconfiguring the server in interesting ways.
	 */
	svc_unreg(NFS_PROGRAM, NFS_VERSION);
	svc_unreg(NFS_PROGRAM, NFS_V3);
	svc_unreg(NFS_PROGRAM, NFS_V4);
	svc_unreg(NFS_ACL_PROGRAM, NFS_ACL_V2);
	svc_unreg(NFS_ACL_PROGRAM, NFS_ACL_V3);

	/*
	 * Set up kernel RPC thread pool for the NFS server.
	 */
	if (nfssvcpool(maxservers)) {
		fprintf(stderr, "Can't set up kernel NFS service: %s. "
		    "Exiting.\n", strerror(errno));
		exit(1);
	}

	/*
	 * Set up blocked thread to do LWP creation on behalf of the kernel.
	 */
	if (svcwait(NFS_SVCPOOL_ID)) {
		fprintf(stderr, "Can't set up NFS pool creator: %s. Exiting.\n",
		    strerror(errno));
		exit(1);
	}

	/*
	 * RDMA start and stop thread.
	 * Per pool RDMA listener creation and
	 * destructor thread.
	 *
	 * start rdma services and block in the kernel.
	 * (only if proto or provider is not set to TCP or UDP)
	 */
	if ((proto == NULL) && (provider == NULL)) {
		if (svcrdma(NFS_SVCPOOL_ID, nfs_server_vers_min,
		    nfs_server_vers_max, nfs_server_delegation)) {
			fprintf(stderr,
			    "Can't set up RDMA creator thread : %s\n",
			    strerror(errno));
		}
	}

	/*
	 * Now open up for signal delivery
	 */

	(void) thr_sigsetmask(SIG_UNBLOCK, &sgset, NULL);
	sigset(SIGTERM, sigflush);
	sigset(SIGUSR1, quiesce);

	/*
	 * Build a protocol block list for registration.
	 */
	protobp0 = protobp = (struct protob *)malloc(sizeof (struct protob));
	protobp->serv = "NFS";
	protobp->versmin = nfs_server_vers_min;
	protobp->versmax = nfs_server_vers_max;
	protobp->program = NFS_PROGRAM;

	protobp->next = (struct protob *)malloc(sizeof (struct protob));
	protobp = protobp->next;
	protobp->serv = "NFS_ACL";		/* not used */
	protobp->versmin = nfs_server_vers_min;
	/* XXX - this needs work to get the version just right */
	protobp->versmax = (nfs_server_vers_max > NFS_ACL_V3) ?
	    NFS_ACL_V3 : nfs_server_vers_max;
	protobp->program = NFS_ACL_PROGRAM;
	protobp->next = (struct protob *)NULL;

	if (allflag) {
		if (do_all(protobp0, nfssvc) == -1) {
			fprintf(stderr, "setnetconfig failed : %s\n",
			    strerror(errno));
			exit(1);
		}
	} else if (proto) {
		/* there's more than one match for the same protocol */
		struct netconfig *nconf;
		NCONF_HANDLE *nc;
		bool_t	protoFound = FALSE;
		if ((nc = setnetconfig()) == (NCONF_HANDLE *) NULL) {
			fprintf(stderr, "setnetconfig failed : %s\n",
			    strerror(errno));
			goto done;
		}
		while (nconf = getnetconfig(nc)) {
			if (strcmp(nconf->nc_proto, proto) == 0) {
				protoFound = TRUE;
				do_one(nconf->nc_device, NULL,
				    protobp0, nfssvc);
			}
		}
		(void) endnetconfig(nc);
		if (protoFound == FALSE) {
			fprintf(stderr,
			    "couldn't find netconfig entry for protocol %s\n",
			    proto);
		}
	} else if (provider)
		do_one(provider, proto, protobp0, nfssvc);
	else {
		for (providerp = defaultproviders;
		    *providerp != NULL; providerp++) {
			provider = *providerp;
			do_one(provider, NULL, protobp0, nfssvc);
		}
	}
done:

	free(protobp);
	free(protobp0);

	if (num_fds == 0) {
		fprintf(stderr, "Could not start NFS service for any protocol."
		    " Exiting.\n");
		exit(1);
	}

	end_listen_fds = num_fds;

	/*
	 * nfsd is up and running as far as we are concerned.
	 */
	daemonize_fini(pipe_fd);

	/*
	 * Get rid of unneeded privileges.
	 */
	__fini_daemon_priv(PRIV_PROC_FORK, PRIV_PROC_EXEC, PRIV_PROC_SESSION,
	    PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, (char *)NULL);

	/*
	 * Poll for non-data control events on the transport descriptors.
	 */
	poll_for_action();

	/*
	 * If we get here, something failed in poll_for_action().
	 */
	return (1);
}
Example #7
0
int main(int argc, char* argv[]) {
    size_t num_voices;
    char **fn_voices;
    char* in_fname;
    char* output_fname;
    FILE * outfp;
    char* dur_fname;
    FILE * durfp;    
    bool print_label = false;
    bool print_utt = false;
    bool write_raw = false;
    bool write_durlabel = false;

    CFSAString LexFileName, LexDFileName;
    HTS_Engine engine;
    double speed = 1.1;
    size_t fr = 48000;
    size_t fp = 240;
    float alpha = 0.55;
    float beta = 0.0;
    float ht = 2.0;
    float th = 0.5;
    float gvw1 = 1.0;
    float gvw2 = 1.2;

    FSCInit();
    fn_voices = (char **) malloc(argc * sizeof (char *));
    
    if (argc < 11) {
        fprintf(stderr, "Viga: liiga vähe parameetreid\n\n");
        PrintUsage();
    }    

    for (int i = 0; i < argc; i++) {
        if (CFSAString("-lex") == argv[i]) {
            if (i + 1 < argc) {
                LexFileName = argv[++i];
            } else {
                return PrintUsage();
            }
        }
        if (CFSAString("-lexd") == argv[i]) {
            if (i + 1 < argc) {
                LexDFileName = argv[++i];
            } else {
                return PrintUsage();
            }
        }
        if (CFSAString("-m") == argv[i]) {
            if (i + 1 < argc) {
                fn_voices[0] = argv[i + 1];
            } else {
                fprintf(stderr, "Viga: puudub *.htsvoice fail\n");
                PrintUsage();
                exit(0);
            }
        }
        if (CFSAString("-o") == argv[i]) {
            if (i + 1 < argc) {
                output_fname = argv[i + 1];
                cfileexists(output_fname);
            } else {
                fprintf(stderr, "Viga: puudb väljundfaili nimi\n");
                PrintUsage();
                exit(0);
            }
        }
        if (CFSAString("-f") == argv[i]) {
            if (i + 1 < argc) {
                in_fname = argv[i + 1];
            } else {
                fprintf(stderr, "Viga: puudb sisendfaili nimi\n");
                PrintUsage();
                exit(0);
            }
        }
        if (CFSAString("-s") == argv[i]) {
            if (i + 1 < argc) {
                samplerate(fr, fp, alpha, atoi(argv[i + 1]));
            }
        }
        if (CFSAString("-r") == argv[i]) {
            if (i + 1 < argc) {
                speed = atof(argv[i + 1]);
            }
        }
        if (CFSAString("-ht") == argv[i]) {
            if (i + 1 < argc) {
                ht = atof(argv[i + 1]);
            }
        }
        if (CFSAString("-gvw1") == argv[i]) {
            if (i + 1 < argc) {
                gvw1 = atof(argv[i + 1]);
            }
        }
        if (CFSAString("-gvw2") == argv[i]) {
            if (i + 1 < argc) {
                gvw2 = atof(argv[i + 1]);
            }
        }        
        if (CFSAString("-debug") == argv[i]) {
            print_label = true;
        }
        if (CFSAString("-utt") == argv[i]) {
            print_utt = true;
        }        
        if (CFSAString("-raw") == argv[i]) {
            write_raw = true;
        }
        if (CFSAString("-dur") == argv[i]) {
            if (i + 1 < argc) {
                dur_fname = argv[i + 1];
                cfileexists(dur_fname);
                write_durlabel = true;                
            } else {
                fprintf(stderr, "Viga: puudb kestustefaili nimi\n");
                PrintUsage();
                exit(0);
            }
        }

        
    }

    Linguistic.Open(LexFileName);
    Disambiguator.Open(LexDFileName);

    CFSWString text;
    ReadUTF8Text(text, in_fname);
    HTS_Engine_initialize(&engine);

    if (HTS_Engine_load(&engine, fn_voices, 1) != TRUE) {
        fprintf(stderr, "Viga: puudub *.htsvoice. %p\n", fn_voices[0]);
        free(fn_voices);
        HTS_Engine_clear(&engine);
        exit(1);
    }
    free(fn_voices);

    HTS_Engine_set_sampling_frequency(&engine, (size_t) fr);
    HTS_Engine_set_phoneme_alignment_flag(&engine, FALSE);
    HTS_Engine_set_fperiod(&engine, (size_t) fp);
    HTS_Engine_set_alpha(&engine, alpha);
    HTS_Engine_set_beta(&engine, beta);
    HTS_Engine_set_speed(&engine, speed);
    HTS_Engine_add_half_tone(&engine, ht);
    HTS_Engine_set_msd_threshold(&engine, 1, th);
    /*
    HTS_Engine_set_duration_interpolation_weight(&engine, 1, diw);
    HTS_Engine_set_parameter_interpolation_weight(&engine, 0, 0, piw1);
    HTS_Engine_set_parameter_interpolation_weight(&engine, 0, 1, piw2);
    HTS_Engine_set_gv_interpolation_weight(&engine, 0, 0, giw1);
    HTS_Engine_set_gv_interpolation_weight(&engine, 0, 1, giw2);
     */
    HTS_Engine_set_gv_weight(&engine, 0, gvw1);
    HTS_Engine_set_gv_weight(&engine, 1, gvw2);

    text = DealWithText(text);
    CFSArray<CFSWString> res = do_utterances(text);

    INTPTR data_size = 0;
    outfp = fopen(output_fname, "wb");
    if (write_durlabel) durfp = fopen(dur_fname, "w");
    if (!write_raw) HTS_Engine_write_header(&engine, outfp, 1);
    for (INTPTR i = 0; i < res.GetSize(); i++) {

        CFSArray<CFSWString> label = do_all(res[i], print_label, print_utt);

        std::vector<std::string> v;
        v = to_vector(label);

        std::vector<char*> vc;
        fill_char_vector(v, vc);

        size_t n_lines = vc.size();

        if (HTS_Engine_synthesize_from_strings(&engine, &vc[0], n_lines) != TRUE) {
            fprintf(stderr, "Viga: süntees ebaonnestus.\n");            
            HTS_Engine_clear(&engine);
            exit(1);
        }

        clean_char_vector(vc);
        data_size += HTS_Engine_engine_speech_size(&engine);
        if (write_durlabel) HTS_Engine_save_durlabel(&engine, durfp);
        HTS_Engine_save_generated_speech(&engine, outfp);

        HTS_Engine_refresh(&engine);

    } //synth loop
    
    if (!write_raw) HTS_Engine_write_header(&engine, outfp, data_size);
    if (write_durlabel) fclose(durfp);
    fclose(outfp);

    HTS_Engine_clear(&engine);
    Linguistic.Close();

    FSCTerminate();
    return 0;

}
Example #8
0
int
main(int argc, char *argv[])
{
	int ch, options = 0, action = CCD_CONFIG;

	while ((ch = getopt(argc, argv, "cCf:guUv")) != -1) {
		switch (ch) {
		case 'c':
			action = CCD_CONFIG;
			++options;
			break;

		case 'C':
			action = CCD_CONFIGALL;
			++options;
			break;

		case 'f':
			ccdconf = optarg;
			break;

		case 'g':
			action = CCD_DUMP;
			break;

		case 'u':
			action = CCD_UNCONFIG;
			++options;
			break;

		case 'U':
			action = CCD_UNCONFIGALL;
			++options;
			break;

		case 'v':
			verbose = 1;
			break;

		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (options > 1)
		usage();

	if (modfind("g_ccd") < 0) {
		/* Not present in kernel, try loading it */
		if (kldload("geom_ccd") < 0 || modfind("g_ccd") < 0)
			warn("geom_ccd module not available!");
	}

	switch (action) {
		case CCD_CONFIG:
		case CCD_UNCONFIG:
			exit(do_single(argc, argv, action));
			/* NOTREACHED */

		case CCD_CONFIGALL:
		case CCD_UNCONFIGALL:
			exit(do_all(action));
			/* NOTREACHED */

		case CCD_DUMP:
			exit(dump_ccd(argc, argv));
			/* NOTREACHED */
	}
	/* NOTREACHED */
	return (0);
}
Example #9
0
WORD main( WORD argc, BYTE *argv[] )
{
	/* Hauptroutine */
	struct time	zeit1, zeit2;
	ERROR_STR	*error_str, *temp_error_str;
	REG ULONG	i, j;
	ULONG		sec1, sec2;
	WORD		state;

	/* Meldung ausgeben */
	puts( INFO );

	/* Zeit merken */
	gettime( &zeit1 );

	/* Zeit in Sekunden umwandeln */
	sec1 = ( zeit1.ti_hour * 3600L ) + ( zeit1.ti_min * 60L ) + zeit1.ti_sec;

	/* Den Dateinamen merken */
	file_name = argv[1];

	/* Hauptroutine aufrufen */
	state = do_all( argv[1] );

	/* Traten Shift-/Reduce-Fehler auf ? */
	if( sr_err || rr_err )
		/* Es traten Shift-Reduce-Fehler auf */
		fprintf( stderr, "\n\n%d Shift-/Reduce-Fehler, %d Reduce-/Reduce-Fehler registriert.", sr_err, rr_err );
	
	/* Ausgabe der Fehler in Datei ? */
	if( lr_info.err_dest == DFILE )
	{
		/* Sind Fehler aufgetreten ? */
		if( error_flag )
			/* Meldung ausgeben */
			fprintf( stderr, "\n\nEs sind Fehler aufgetreten !" );

		else
			/* Meldung ausgeben */
			fprintf( stderr, "\n\nEs sind keine Fehler aufgetreten !" );
	}

	/* Speicher freigeben */
	if( grammar )
		/* Speicher der Grammatikdatei freigeben */
		free( ( VOID * ) grammar );

	if( error_struct )
	{
		/* Speicher der ERROR-Strukturen freigeben */
		for( i = 0; i < error_struct_count; i++ )
		{
			/* Zeiger auf ERROR_STR holen */
			error_str = error_struct[i];

			/* Muss noch Speciher freigegeben werden ? */
			while( error_str )
			{
				/* Folge-Struktur merken */
				temp_error_str = error_str->error_str;

				/* Speicher des Fehlermeldung-Textes freigeben */
				free( ( VOID * ) error_str->err_msg );

				/* Speicher der aktuellen ERROR_STR freigeben */
				free( ( VOID * ) error_str );

				/* Pointer umkopieren */
				error_str = temp_error_str;
			}
		}
	}

	if( hulle_str )
	{
		/* Speicher s�mtlicher H�llen freigeben */
		for( i = 0; i <= hulle_count; i++ )
		{
			/* Das Lookahead-Array aller Items freigeben */
			for( j = 0; j < hulle_str[i]->anz_items; j++ )
				/* Speicher freigeben */
				free( ( VOID * ) hulle_str[i]->item_str[j].lookahead.term_arr );

			/* Speicher der ITEM_STR freigeben */
			free( ( VOID * ) hulle_str[i]->item_str );
		}
	}

	if( lr_tab )
	{
		/* Speicher der LR-Tabelle freigeben */
		for( i = 0; i <= hulle_count; i++ )
			free( ( VOID * ) lr_tab[i] );

		/* Den Speicher des Arrays freigeben */
		free( ( VOID * ) lr_tab );
	}

	if( jump_tab )
		/* Speicher der Zustandsueberg�nge freigeben */
		free( ( VOID * ) jump_tab );

	if( ziel_tab )
		/* Speicher der Ziel-Tabelle freigeben */
		free( ( VOID * ) ziel_tab );

	if( nterm_str )
	{
		/* Speicher s�mtlicher NTERM_STRs zurueckgeben */
		for( i = 1; i <= nterm_count; i++ )
		{
			/* Die FOLLOW-Elemente freigeben */
			free( ( VOID * ) nterm_str[i]->follow.term_arr );

			/* Die NTERM_STR-Struktur freigeben */
			free( ( VOID * ) nterm_str[i] );
		}

		/* Den Speicher des Arrays freigeben */
		free( ( VOID * ) nterm_str );
	}

	if( term_str )
		/* Speicher der Terminale freigeben */
		free( ( VOID * ) term_str );

	if( prod_index_arr )
		/* Speicher der Indexe der Produktionen freigeben */
		free( ( VOID * ) prod_index_arr );

	if( gra_err_str )
		/* Speicher freigeben */
		free( ( VOID * ) gra_err_str );

	if( nterm_first )
	{
		/* Speicher der FIRST-Elemente freigeben */
		for( i = 0; i < nterm_first_count; i++ )
		{
			/* Speicher der FIRST-Terminale freigeben */
			free( ( VOID * ) nterm_first[i]->first.term_arr );
			free( ( VOID * ) nterm_first[i] );
		}

		/* Den Speicher des Arrays freigeben */
		free( ( VOID * ) nterm_first );
	}

	if( old_nterm_index )
		/* Speicher freigeben */
		free( ( VOID * ) old_nterm_index );

	if( init )
		/* Speicher freigeben */
		free( ( VOID * ) init );

	if( incl )
		/* Speicher freigeben */
		free( ( VOID * ) incl );

	if( error_hulle )
		/* Speicher freigeben */
		free( ( VOID * ) error_hulle );

	if( type_arr )
	{
		/* Alle Eintr�ge freigeben */
		for( i = 0; i < type_arr_count; i++ )
			/* Speicher freigeben */
			free( ( VOID * ) type_arr[i] );

		/* Speicher des Arrays freigeben */
		free( ( VOID * ) type_arr );
	}

	if( sem_act )
	{
		/* Alle Eintr�ge freigeben */
		for( i = 0; i < sem_act_count; i++ )
			/* Speicher freigeben */
			free( ( VOID * ) sem_act[i].sem_act_text );

		/* Speicher des Arrays freigeben */
		free( ( VOID * ) sem_act );
	}

	if( hash_tab )
	{
		/* Speicher der HASH-Tabelle freigeben */
		for( i = 0; i < lr_info.hash_tab_size; i++ )
		{
			/* Ist etwas eingetragen ? */
			if( hash_tab[i].name )
			{
				/* Ja, Speicher freigeben */
				free( ( VOID * ) hash_tab[i].name );
				free( ( VOID * ) hash_tab[i].term_str );
				free( ( VOID * ) hash_tab[i].hulle_arr );
			}

			/* Speicher der eigentlichen HASH-Tabelle freigeben */
			free( ( VOID * ) hash_tab );
		}
	}

	/* Datei schliessen */
	if( handle != -1 )
	{
		/* Datei schliessen */
		if( close( handle ) < 0 )
			/* Fehler */
			return( error( CANNOT_CLOSE_GRAMMAR_FILE, 0, 0 ) );
	}

	/* Parser-Source-Datei schliessen ? */
	if( parser_file )
	{
		/* Datei schliessen */
		if( fclose( parser_file ) == EOF )
			/* Fehler */
			return( error( CANNOT_CLOSE_PARSER_FILE, 0, 0 ) );
	}

	/* BNF-Grammatik-Datei schliessen ? */
	if( bnf_file )
	{
		/* Datei schliessen */
		if( fclose( bnf_file ) == EOF )
			/* Fehler */
			return( error( CANNOT_CLOSE_BNF_FILE, 0, 0 ) );
	}

	/* Ist ein Fehler aufgetreten ? */
	if( state < 0 )
		/* Fehler */
		return( -1 );

	/* Zeit holen */
	gettime( &zeit2 );

	/* Zeit in Sekunden umwandeln */
	sec2 = ( zeit2.ti_hour * 3600L ) + ( zeit2.ti_min * 60L ) + zeit2.ti_sec;

	/* Zeit merken */
	fprintf( file, "\n\nBen�tigte Zeit: %02lu:%02lu:%02lu", ( sec2 - sec1 ) / 3600L, ( ( sec2 - sec1 ) % 3600L ) / 60L, ( ( sec2 - sec1 ) % 3600L ) % 60L );

	/* Ausgabe auf Bildschirm ? */
	if( lr_info.dest == DSCREEN )
		/* Auf Tastendruck warten */
		Cnecin();

	/* Datei schliessen */
	if( fclose( file ) < 0 )
		/* Fehler */
		return( error( CANNOT_CLOSE_FILE, 0, 0 ) );

	/* Fehler-Datei schliessen */
	if( fclose( err_file ) < 0 )
		/* Fehler */
		return( error( CANNOT_CLOSE_ERR_FILE, 0, 0 ) );

	/* Alles OK */
	return( 0 );
}
Example #10
0
int main(int argc, char **argv)
{
	struct ut_cache **cache = NULL;
	int num_cache = 0;
	int c = 0;
	int action = UT_NO_TASK;
	int interactive = false;
	int game_type = 0;

	char *home_dir;
	home_dir = getenv("HOME");

	char cache_file[MAXLEN];
	memset( cache_file, 0, sizeof(cache_file));
	char tmp_cache[MAXLEN];
	memset( tmp_cache, 0, sizeof(tmp_cache));
	char tmp_config[MAXLEN];
	memset( tmp_config, 0, sizeof(tmp_config));
	char tmp_move[MAXLEN];
	memset( tmp_move, 0, sizeof(tmp_move));

	cache_dir = NULL;
	move_dir = NULL;
	config_dir = NULL;

	/* Handle args */
	while( (c = getopt_long(argc, argv, "adhivb:c:", long_options, NULL)) != -1 ) {
		switch (c) {
		case 'a':
			if(!action)
				action = UT_MOVE;
			else
				usage("can't move and delete all.");
			break;
		case 'b':
			move_dir = optarg;
			break;
		case 'c':
			config_dir = optarg;
			break;
		case 'd':
			if(!action)
				action = UT_DELETE;
			else
				usage("can't move and delete all.");
			break;
		case 'i':
			interactive = true;
			break;
		case 'v':
			//TODO: verbose echos move or delete action
			break;
		case UT99:
			if(!game_type)
				game_type = UT99;
			else
				usage("only one game type at a time");
			break;
		case UT2003:
			if(!game_type)
				game_type = UT2003;
			else
				usage("only one game type at a time");
			break;
		case UT2004:
			if(!game_type)
				game_type = UT2004;
			else
				usage("only one game type at a time");
			break;
		case 'h':
		default:
			usage(ut_cache_usage_string);
		}
	}

	if( config_dir == NULL ) {
		switch(game_type) {
		case UT99:
			memcpy( tmp_config, home_dir, strlen(home_dir) * sizeof(char) );
			strcat( tmp_config, "/.loki/ut");
			config_dir = tmp_config;
			break;
		case UT2003:
			memcpy( tmp_config, home_dir, strlen(home_dir) * sizeof(char) );
			strcat( tmp_config, "/.ut2003");
			config_dir = tmp_config;
			break;
		case UT2004:
			memcpy( tmp_config, home_dir, strlen(home_dir) * sizeof(char) );
			strcat( tmp_config, "/.ut2004");
			config_dir = tmp_config;
			break;
		default:
			usage(ut_cache_usage_string);
			break;
		}
	}
	memcpy( tmp_cache, config_dir, strlen(config_dir) * sizeof(char));
	strcat( tmp_cache, "/Cache" );
	cache_dir = tmp_cache;
	fprintf(stderr, "using \"%s\" for cache directory\n", cache_dir);

	if( move_dir == NULL ) {
		move_dir = config_dir;
		fprintf(stderr, "no move directory specified. using \"%s\"\n", move_dir);
	}

	memcpy( cache_file, cache_dir, strlen(cache_dir) * sizeof(char));
	strcat( cache_file, "/cache.ini" );
	cache = read_cache( cache_file, &num_cache);
	if( cache == NULL ) {
		return 1;
	}

	if( interactive ) {
		do_interactive( cache, num_cache );
	}else{
		do_all( cache, num_cache, action );
	}

	return 0;
}
Example #11
0
int
main(int argc, char *argv[])
{
	int pid;
	int i;
	struct protob *protobp;
	struct flock f;
	pid_t pi;
	struct svcpool_args cb_svcpool;

	MyName = "nfs4cbd";
	Mysvc4 = nfs4svc;

#ifndef	DEBUG
	/*
	 * Close existing file descriptors, open "/dev/null" as
	 * standard input, output, and error, and detach from
	 * controlling terminal.
	 */
	closefrom(0);
	(void) open("/dev/null", O_RDONLY);
	(void) open("/dev/null", O_WRONLY);
	(void) dup(1);
	(void) setsid();
#endif

	/*
	 * create a child to continue our work
	 * Parent's exit will tell mount command we're ready to go
	 */
	if ((pi = fork()) > 0) {
		exit(0);
	}

	if (pi == -1) {
		(void) syslog(LOG_ERR,
			"Could not start NFS4_CALLBACK service");
		exit(1);
	}

	(void) _create_daemon_lock(NFS4CBD, DAEMON_UID, DAEMON_GID);

	svcsetprio();

	if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET,
	    DAEMON_UID, DAEMON_GID, PRIV_SYS_NFS, (char *)NULL) == -1) {
		(void) fprintf(stderr, "%s must be run with sufficient"
			" privileges\n", argv[0]);
		exit(1);
	}
	/* Basic privileges we don't need, remove from E/P. */
	__fini_daemon_priv(PRIV_PROC_EXEC, PRIV_PROC_FORK, PRIV_FILE_LINK_ANY,
	    PRIV_PROC_SESSION, PRIV_PROC_INFO, (char *)NULL);

	/*
	 * establish our lock on the lock file and write our pid to it.
	 * exit if some other process holds the lock, or if there's any
	 * error in writing/locking the file.
	 */
	pid = _enter_daemon_lock(NFS4CBD);
	switch (pid) {
	case 0:
		break;
	case -1:
		syslog(LOG_ERR, "error locking for %s: %s", NFS4CBD,
		    strerror(errno));
		exit(2);
	default:
		/* daemon was already running */
		exit(0);
	}

	openlog(MyName, LOG_PID | LOG_NDELAY, LOG_DAEMON);

	cb_svcpool.id = NFS_CB_SVCPOOL_ID;
	cb_svcpool.maxthreads = 0;
	cb_svcpool.redline = 0;
	cb_svcpool.qsize = 0;
	cb_svcpool.timeout = 0;
	cb_svcpool.stksize = 0;
	cb_svcpool.max_same_xprt = 0;

	/* create a SVC_POOL for the nfsv4 callback deamon */
	if (_nfssys(SVCPOOL_CREATE, &cb_svcpool)) {
		(void) syslog(LOG_ERR, "can't setup NFS_CB SVCPOOL: Exiting");
		exit(1);
	}

	/*
	 * Set up blocked thread to do LWP creation on behalf of the kernel.
	 */
	if (svcwait(NFS_CB_SVCPOOL_ID)) {
		(void) syslog(LOG_ERR,
		    "Can't set up NFS_CB LWP creator: Exiting");
		exit(1);
	}


	/*
	 * Build a protocol block list for registration.
	 */
	protobp = (struct protob *)malloc(sizeof (struct protob));
	protobp->serv = "NFS4_CALLBACK";
	protobp->versmin = NFS_CB;
	protobp->versmax = NFS_CB;
	protobp->program = NFS4_CALLBACK;
	protobp->next = NULL;

	if (do_all(protobp, NULL, 0) == -1) {
		exit(1);
	}

	free(protobp);

	if (num_fds == 0) {
		(void) syslog(LOG_ERR,
		"Could not start NFS4_CALLBACK service for any protocol");
		exit(1);
	}

	end_listen_fds = num_fds;
	/*
	 * Poll for non-data control events on the transport descriptors.
	 */
	poll_for_action();

	/*
	 * If we get here, something failed in poll_for_action().
	 */
	return (1);
}
Example #12
0
int main(int argc, char **argv)
{
    /* Prepares globally used data on program start_up */
    int number_of_lines = 0, number_of_matches = 0, number_of_rounds = 0, match_number = 0, user_input = 0;
    char **file_string, early[STR_LEN2], late[STR_LEN2], weekday[STR_LEN];
    match_s *match; /* Note: Array declared, but not allocated or initialized */
    team_s *team; /* Note: Array declared, but not allocated or initialized */

    get_number_of_lines(&number_of_lines);
    get_number_of_matches(number_of_lines, &number_of_matches);
    get_number_of_rounds(number_of_lines, &number_of_rounds);
    file_string = (char **)calloc(number_of_lines,sizeof(char *));
    for(match_number = 0; match_number < number_of_matches; match_number++) {
        file_string[match_number] = (char *)calloc(LINE_LENGTH,sizeof(char));
    }
    read_file(file_string);
    match = (match_s *)calloc(number_of_matches,sizeof(match_s));
    save_file_to_struct(match, file_string, number_of_lines);

    team = (team_s *)calloc(NUMBER_OF_TEAMS,sizeof(team_s));
    get_teams(team, match, number_of_matches);

    /* Run program with user interaction */

    if(argc == 2 && strcmp(argv[1], "--print") == 0) {
        do_all(match, team, number_of_matches, number_of_rounds);
    } else {
        printf("Please input a numner between 1 and 6 to run said program.\nInput 0 to exit the program:\n");
        printf("Input:>> ");
        scanf("%d",&user_input);

        while(user_input != 0) {

            switch (user_input) {
            case 1:
                printf("\nTask one:\n");
                printf("Print all matches that has 7 or more goals total:\n");
                task_one(match, number_of_matches);
                break;
            case 2:
                printf("\nTask two:\n");
                printf("Print the first round with most goals.\n");
                task_two(match, number_of_rounds);
                break;
            case 3:
                printf("\nTask three:\n");
                printf("Get the teams that win more mathces out than home:\n");
                task_three(team);
                break;
            case 4:
                printf("Task four:\n");
                printf("Print the team with fewest spectators when playing home.\n");
                task_four(team);
                break;
            case 5:
                printf("Task five:\n");
                printf("Print the matches in a specific time interval, and sort them by number of goals.\n");
                prompt_time(early, late, weekday);
                task_five(match, number_of_matches, early, late, weekday);
                break;
            case 6:
                printf("Task six:\n");
                printf("Print the result for the end of the season.\n");
                task_six(team, number_of_rounds);
                break;
            default:
                printf("Invalid user input!\n");
                break;
            }

            user_input = 0;

            printf("\nTo perform another task, input a number from 1 - 6.\nTo exit, input 0.\n");
            printf("Input:>> ");
            scanf("%d",&user_input);
        }
    }

    free(match);
    free(team);

    return 0;
}