Пример #1
0
int nodeup_postmove(int argc, char *argv[]) {
    int i, len, fd;
    char *path, *val;

    if (argc < 3) {
	log_print(LOG_ERROR, "ERROR: Usage: sysctl key value\n");
	return -1;
    }

    if (nodeup_mnt_proc(PROC_TMP))
	return -1;

    /* Arg 1 is the path */
    path = alloca(strlen(argv[1])+strlen(PROC_TMP "/sys/") + 1);
    strcpy(path, PROC_TMP "/sys/");
    strcat(path, argv[1]);

    /* Change dots to slashes in the path */
    for (i=strlen(PROC_TMP "/sys/"); path[i]; i++)
	if (path[i] == '.') path[i] = '/';

    /*log_print(LOG_DEBUG, "PATH: %s\n", path);*/
    
    /* Build the value */
    len = 0;
    for (i=2; i < argc; i++)
	len += strlen(argv[i]) + 1;

    /*log_print(LOG_DEBUG, "VAL LEN: %d\n", len);*/

    val = alloca(len);
    val[0] = 0;
    for (i=2; i+1 < argc; i++) {
	strcat(val, argv[i]);
	strcat(val, " ");
    }
    strcat(val, argv[i]);

    log_print(LOG_INFO, "setting %s = \"%s\"\n", argv[1], val);

    /* Do the sysctl write */
    fd = open(path, O_WRONLY);
    if (fd == -1) {
	log_print(LOG_ERROR, "%s: %s\n", path, strerror(errno));
	return -1;
    }
    if (write(fd, val, strlen(val)) != strlen(val)) {
    	log_print(LOG_ERROR, "write(%s): %s\n", path, strerror(errno));
	close(fd);
	return -1;
    }
    close(fd);
    return 0;
}
Пример #2
0
int nodeup_postmove(int argc, char *argv[]) {
    int c, i;

    if (nodeup_mnt_proc(PROC_TMP))
	return -1;

    while ((c = getopt(argc, argv, "")) != -1) {
	switch (c) {
	    
	default:
	    return -1;
	}
    }

    for (i=optind; i < argc; i++) {
	log_print(LOG_INFO, "performing RARP on %s\n", argv[i]);
	if (rarp(argv[i], 1, 5*60))
	    return -1;
    }
    return 0;
}
Пример #3
0
int nodeup_postmove(int argc, char *argv[])
{
	FILE *f;
	char line[200];
	int i, j;
	long long values[3] = { 0, 0, 0 };

	static char *files[] = { PROC_TMP "/cpuinfo", PROC_TMP "/meminfo", 0 };
	struct info_t {
		char *fmt;
		long long *value;
		long long scale;
	} info[] = {
#if defined(__alpha__)
		{
		"cpus active             : %Ld", &values[0], 1}, {
		"cycle frequency [Hz]    : %Ld", &values[1], 1},
#endif
#if defined(__i386__) || defined(__x86_64__)
		{
		"cpu MHz         : %Ld", &values[1], 1000000}, {
		"processor\t:", &values[0], 0},
#endif
#if defined(__powerpc64__) || defined(powerpc)
		{
		"clock\t\t: %Ld", &values[1], 1000000}, {
		"processor\t:", &values[0], 0},
#endif
		{
		"MemTotal: %Ld", &values[2], 1024}, {
		0}
	};

	if (nodeup_mnt_proc(PROC_TMP))
		return -1;

	for (i = 0; files[i]; i++) {
		if (!(f = fopen(files[i], "r"))) {
			perror(files[i]);
			exit(1);
		}
		while (fgets(line, 100, f)) {
			for (j = 0; info[j].fmt; j++) {
				if (info[j].scale &&
				    sscanf(line, info[j].fmt,
					   info[j].value) == 1) {
					(*info[j].value) *= info[j].scale;
					break;
				}
				if (!info[j].scale &&
				    strncmp(info[j].fmt, line,
					    strlen(info[j].fmt)) == 0) {
					(*info[j].value)++;
					break;
				}
			}
		}
		fclose(f);
	}

	log_print(LOG_INFO, "cpus=%Ld; hz=%Ld; mem=%Ld\n",
		  values[0], values[1], values[2]);

	nodeup_rpc(store_info_callback, values, sizeof(values), 0, 0);
	return 0;
}