Exemple #1
0
/*
 *  qnx_vc_name_attach
 *
 *  Note that currently the only valid values for nid are 0 and the
 *  local nid.
 */
int
qnx_vc_name_attach(nid_t nid, unsigned length, char *name)
{
	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	if (nid == 0)
		nid = getnid();
	return qnx_name_locate(nid, name, length, NULL);
}
Exemple #2
0
/*
 *  qnx_name_locate
 *
 *  Note that currently the only valid values for nid are 0 and the
 *  local nid.
 */
int
qnx_name_locate(nid_t nid, char *name, unsigned size, unsigned *copies)
{
	procmgr_msg_t   msg;
	procmgr_reply_t reply;

	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	msg.hdr.type = _IO_MSG;
	msg.hdr.combine_len = sizeof(msg.hdr);
	msg.hdr.mgrid = MGR_ID_PROCMGR;
	msg.hdr.subtype = _PROCMGR_QNX_NAME_LOCATE;
	msg.un.locate.nid = nid; /* 0 */
	msg.un.locate.vc_size = size;
	strncpy(msg.un.locate.name, name, _NAME_MAX_LEN);
	msg.un.locate.name[_NAME_MAX_LEN] = '\0';
	if (MsgSend(magic.procmgr_fd, &msg, sizeof(msg), &reply, sizeof(reply)) == -1)
		return -1;
	errno = reply.set_errno_to_this;
	if (copies)
		*copies = reply.un.locate.copies;
	return reply.un.locate.pid;
}
Exemple #3
0
void DeviceInit()
{
	int unit;
	dev_t rdev = qnx_device_attach();

	if(rdev == -1)
		Error("qnx_device_attach failed: [%d] %s\n", ERR(errno));

	for(unit = 0; unit < sizeof(units)/sizeof(Device); ++unit) {
		Device* d = Unit(unit);
		struct stat* s = &d->stat;

		s->st_ino	= unit;
		s->st_dev	= (getnid() << 16) | (rdev << 10) | unit;
		s->st_rdev	= s->st_dev;
		s->st_ouid	= geteuid();
		s->st_ogid	= getegid();
		s->st_ftime	=
		s->st_mtime	=
		s->st_atime	= 
		s->st_ctime	= time(0);
		s->st_mode	= S_IFCHR | 0444; /* r-- r-- r-- */
		s->st_nlink	= 1;
	}
	/* despite the loop above, we only have 2 units, one unlimited,
	* one not.
	*/
	assert(unit == 2);
	link_count = unit;

	units[UNIT_RANDOM].unlimited = 0;
	units[UNIT_URANDOM].unlimited = 1;
}
Exemple #4
0
const char * PMAPI PM_getMachineName(void)
{
    static char buf[128];
#ifdef __QNXNTO__
    gethostname(buf, sizeof (buf));
#else
    sprintf(buf,"node%d", getnid());
#endif
    return buf;
}
Exemple #5
0
/*
 *  qnx_vc_attach
 *
 *  Note that virual circuits are not currently implemented.  The
 *  only valid value for pid is the process id of a local process
 *  and the only valid values for nid are 0 and the local nid.
 */
int
qnx_vc_attach(nid_t nid, pid_t pid, unsigned length, int flags)
{
	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	if (kill(pid, 0) != 0) {
		errno = ESRCH;
		return -1;
	}
	return pid;
}
Exemple #6
0
const char * PMAPI PM_getSNAPConfigPath(void)
{
    static char path[512];
    char        *env;
#ifdef __QNXNTO__
    char temp[64];
    gethostname(temp, sizeof (temp));
    temp[sizeof (temp) - 1] = '\0';     /* Paranoid */
    sprintf(path,"/etc/config/scitech/%s/config", temp);
#else
    sprintf(path,"/etc/config/scitech/%d/config", getnid());
#endif
    if ((env = getenv("SNAP_PATH")) != NULL) {
        strcpy(path,env);
        PM_backslash(path);
        strcat(path,"config");
        }
    return path;
}
Exemple #7
0
/*
 *  qnx_name_detach
 *
 *  Note that currently the only valid values for nid are 0 and the
 *  local nid.
 */
int
qnx_name_detach(nid_t nid, int name_id)
{
	procmgr_msg_t   msg;
	procmgr_reply_t reply;

	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	msg.hdr.type = _IO_MSG;
	msg.hdr.combine_len = sizeof(msg.hdr);
	msg.hdr.mgrid = MGR_ID_PROCMGR;
	msg.hdr.subtype = _PROCMGR_QNX_NAME_DETACH;
	msg.un.detach.nid = nid;
	msg.un.detach.name_id = name_id;
	if (MsgSend(magic.procmgr_fd, &msg, sizeof(msg), &reply, sizeof(reply)) == -1)
		return -1;
	errno = reply.set_errno_to_this;
	return reply.un.detach.retval;
}
Exemple #8
0
/*
 *  qnx_name_attach
 *
 *  Note that currently the only valid values for nid are 0 and the
 *  local nid.
 */
int
qnx_name_attach(nid_t nid, char *name)
{
	procmgr_msg_t   msg;
	procmgr_reply_t reply;

	if (nid != 0 && nid != getnid()) {
		errno = EHOSTUNREACH;
		return -1;
	}
	msg.hdr.type = _IO_MSG;
	msg.hdr.combine_len = sizeof(msg.hdr);
	msg.hdr.mgrid = MGR_ID_PROCMGR;
	msg.hdr.subtype = _PROCMGR_QNX_NAME_ATTACH;
	msg.un.attach.nid = nid;
	strncpy(msg.un.attach.user_name_data, name, _NAME_MAX_LEN);
	msg.un.attach.user_name_data[_NAME_MAX_LEN] = '\0';
	if (MsgSend(magic.procmgr_fd, &msg, sizeof(msg), &reply, sizeof(reply)) == -1)
		return -1;
	errno = reply.set_errno_to_this;
	return reply.un.attach.name_id;
}
Exemple #9
0
/*
 * AutoSaveInit - initialize for auto-save
 */
void AutoSaveInit( void )
{
    char        path[FILENAME_MAX];
    char        path2[FILENAME_MAX];
    char        as_path[FILENAME_MAX];
    char        asl_path[FILENAME_MAX];
    int         len;
    int         cnt;
    FILE        *f;
    int         pid;
    int         ch;
    int         handle;
    int         off;
//    int         old_len;
    int         i;

    /*
     * initialize tmpname
     */
#ifdef __UNIX__
    strcpy( currTmpName,"aaaaaaaaaaaa.tmp" );
#else
    strcpy( currTmpName,"aaaaaaaa.tmp" );
#endif
    pid = getpid();
    itoa( pid, path, 36 );
    len = strlen( path );
    memcpy( &currTmpName[TMP_FNAME_LEN - len], path, len );
#ifdef __QNX__
    {
        int     len2, len3;
        int     nid, uid;

        nid = getnid();
        itoa( nid, path, 36 );
        len2 = strlen( path );
        memcpy( &currTmpName[TMP_FNAME_LEN - len - len2], path, len2 );

        uid = getuid();
        itoa( uid, path, 36 );
        len3 = strlen( path );
        memcpy( &currTmpName[TMP_FNAME_LEN - len - len2 - len3], path, len3 );
        memcpy( &checkFileName[EXTRA_EXT_OFF], path, len3 );
        memcpy( &checkFileTmpName[EXTRA_EXT_OFF], path, len3 );
        memcpy( &lockFileName[EXTRA_EXT_OFF], path, len3 );
    }
#endif

    /*
     * check if we need to recover lost files
     */
    if( EditFlags.RecoverLostFiles ) {
        cnt = 0;
        MakeTmpPath( as_path, checkFileName );
        MakeTmpPath( asl_path, lockFileName );
        off = strlen( as_path ) - 5;
        for( ch = START_CHAR; ch <= END_CHAR; ch++ ) {
            as_path[off] = ch;
            asl_path[off] = ch;
            handle = sopen3( as_path, O_RDONLY | O_TEXT, SH_DENYRW );
            if( handle < 0 ) {
                continue;
            }
            f = fdopen( handle, "r" );
            if( f != NULL ) {
                while( fgets( path2, FILENAME_MAX, f ) != NULL ) {
                    for( i = strlen( path2 ); i && isWSorCtrlZ( path2[i - 1] ); --i ) {
                        path2[i - 1] = '\0';
                    }
                    NextWord1( path2, path );
                    RemoveLeadingSpaces( path2 );
                    NewFile( path, FALSE );
                    AddString2( &(CurrentFile->name), path2 );
                    SetFileWindowTitle( CurrentWindow, CurrentInfo, TRUE );
                    FileSPVAR();
                    CurrentFile->modified = TRUE;
                    CurrentFile->check_readonly = TRUE;
                    FTSRunCmds( path2 );
                    cnt++;
                }
                fclose( f );
                remove( as_path );
            } else {
                close( handle );
            }
            remove( asl_path );
        }
        if( cnt == 0 ) {
            MyPrintf( "No files recovered!\n" );
            ExitEditor( -1 );
        }
        Message1( "%d files recovered", cnt );

    }
    if( EditVars.AutoSaveInterval == 0 ) {
        return;
    }

//    old_len = strlen( lockFileName );
    MakeTmpPath( path, lockFileName );
    len = strlen( path ) - strlen( lockFileName );
    off = len + CHAR_OFF;
    for( ch = START_CHAR; ch <= END_CHAR; ch++ ) {
        path[off] = ch;
        lockFileHandle = sopen4( path, O_CREAT | O_TRUNC | O_RDWR | O_TEXT, SH_DENYRW, PMODE_RW );
        if( lockFileHandle > 0 ) {
            break;
        }
    }
    if( lockFileHandle < 0 ) {
        // MyPrintf( "Too many editors running!\n" );
        MyPrintf( "Error opening temp file - '%s'\n", strerror( errno ) );
        ExitEditor( -1 );
    }
    lockFileName[CHAR_OFF] = ch;
    checkFileName[CHAR_OFF] = ch;
    checkFileTmpName[CHAR_OFF] = ch;

} /* AutoSaveInit */
Exemple #10
0
int
main(int argc, char **argv)
{
    /* first allow everyone to purge files created by me */
    umask(0);

    MPI_Init(&argc, &argv);
    double t0 = MPI_Wtime();

    t_bcast = 0;
    t_tar = 0;
    t_init = 0;

    int nid = getnid();
    initialize(nid);

    t_init = MPI_Wtime() - t0;

    t0 = MPI_Wtime();

    int ch;
    extern char * optarg;
    extern int optind;     
    char * PREFIX = "/dev/shm/python";
    fnlist.next = NULL; 

    while((ch = getopt(argc, argv, "vtf:p:")) != -1) {
        switch(ch) {
            case 'v':
                VERBOSE = 1;
                break;
            case 't':
                TIME = 1;
                break;
            case 'p':
                PREFIX = optarg;
                break;
            case 'f':
                {
                    struct fnlist * p = malloc(sizeof(fnlist));
                    p->next = fnlist.next;
                    fnlist.next = p;
                    p->path = strdup(optarg);
                }
                break;
            case '?':
                if(ThisTask == 0) {
                    fprintf(stderr, "usage: bcast [-v] [-f filelist] [-p /dev/shm/python] [packages ...]\n");
                }
                goto quit;
        }
    }

    if(ThisTask == 0) {
        if(VERBOSE) {
            printf("tmpdir:%s\n", PREFIX);
            fflush(stdout);
        }
    }

    if(NodeRank == 0) {
        _mkdir(PREFIX);
    }

    MPI_Barrier(MPI_COMM_WORLD);

    struct fnlist * p;
    for(p = fnlist.next; p ; p = p->next) {
        process_file(p->path, PREFIX);
    }
    int i;
    for(i = optind; i < argc; i ++) {
        bcast(argv[i], PREFIX);
    }

    if(ThisTask == 0) 
    if(TIME) {
        printf("Time : %g in init\n", t_init);
        printf("Time : %g in bcast\n", t_bcast);
        printf("Time : %g in tar\n", t_tar);
        printf("Time : %g in total \n", MPI_Wtime() - t0);
    }
quit:
    MPI_Barrier(MPI_COMM_WORLD);

    MPI_Finalize();
    return 0;
}
Exemple #11
0
int main(int argc, char **argv) {
    char crontab[11 + LOGIN_NAME_MAX] = "crontabs/";/* partial pathname */
    struct passwd *pwent;			/* passwd struct */
    int ch;					/* option character */
    FILE *tab, *tmp = NULL;			/* output/input files */
    int action = CREATE;

#ifdef __WATCOMC__
    nid_t nid = 0, qnx_strtonid();	/* server node */
    pid_t server;
    int local = 0;

    argv0 = basename(argv[0]);
    pwent = getpwuid(getuid());
    umask(066);

    while ((ch = getopt(argc, argv, "d:en:lLru:")) != EOF) {
	switch (ch) {
	  case 'L':
	    nid = getnid();
	    local = !local;
	    break;
	  case 'n':
	    nid = qnx_strtonid(optarg);
	    local = !local;
	    break;
#else
    void * server = NULL;
    int fd;					/* shm_open file handle */
    int euid, egid;

    argv0 = basename(argv[0]);
    pwent = getpwuid(getuid());
    umask(066);

    while ((ch = getopt(argc, argv, "d:elru:")) != EOF) {
	switch (ch) {
#endif
	  case 'd':
	    crondir = optarg;
	    break;
	  case 'e':
	    action = EDIT;
	    break;
	  case 'l':
	    if (action == REMOVE)
		fatal_message("conflict: -r/-l");
	    action = LIST;
	    break;
	  case 'r':
	    if (action == LIST) {
		fatal_message("conflict: -r/-l");
	    }
	    action = REMOVE;
	    break;
	  case 'u':
	    /* get name and uid/gid for user */
	    if ((pwent = getpwnam(optarg)) == 0) {
		long id = strtol(optarg, (char **) &pwent, 10);

		if (*(char *) pwent != 0) {
		    fatal_message("%s %s", "invalid user", optarg);
		}
		if ((pwent = getpwuid(id)) == 0) {
		    fatal_message("%s %s", "unknown user", optarg);
		}
	    }
	    break;
	  default:
	    exit(EXIT_FAILURE);
	}
    }

    /* make sure we're allowed to do anything with this crontab */
    if (getuid() != pwent->pw_uid && getuid() != 0) {
	fatal_message("access denied to crontab for %s", pwent->pw_name);
    }

    /* Locate the server */
#ifdef __WATCOMC__ 
    switch (nid) {
      case 0:
	if ((server = qnx_name_locate(0, cronsrv + 1, 0, 0)) != -1) {
	    nid = getnid();
	    local++;
	    break;
	}
	/* fallthru */
      default:
	server = qnx_name_locate(nid, cronsrv + local, 0, 0);
    }

    if (server == -1)
	fprintf(stderr, "warning: cron has not been started\n");

    if (local) {
	crondir = malloc(strlen(optarg = crondir) + 8);
	sprintf(crondir, "%s.%ld", optarg, nid);
    }

#else
    /* check if cron server is running. */
    if ((fd = shm_open(SHM_CRON, O_RDONLY, S_IRWXU )) == -1) {
	fprintf(stderr, "warning: cron has not been started\n");
    }
    else if(MAP_FAILED == (server = mmap(0, sizeof(pid_t), PROT_READ, MAP_SHARED, fd, 0))) {
	fatal_message("mmapp: %s", strerror(errno));
    }

    if(server && kill(*(pid_t *)server, 0) == -1) {
	fatal_message("cron stopped abnormally");
    }
    close(fd);
#endif

    strcat(crontab, pwent->pw_name);

    if (optind == argc) {
	if (action == CREATE || action == EDIT) {
	    char work[] = "/tmp/cronXXXX";

	    mktemp(work);

	    if (action == CREATE) {
		/* read replacement crontab from stdin */
		tmp = fopen(work, "w+");
		while ((ch = getchar()) != EOF)
		    fputc(ch, tmp);
	    } else {
		char *editor = getenv("EDITOR");
		int status;

		if (editor == NULL)
		    editor = "vi";

		if (chdir(crondir) == -1)
		    fatal_message("%s: %s", crondir, strerror(errno));

		if ((tab = fopen(crontab, "r")) == 0 && errno != ENOENT) {
		    fatal_message("%s/%s: %s", crondir, pwent->pw_name, strerror(errno));
		}

		egid = getegid();
		euid = geteuid();
		setegid(getgid());
		seteuid(getuid());

		tmp = fopen(work, "w+");
		if (tab) {
		    while ((ch = fgetc(tab)) != EOF)
			fputc(ch, tmp);
		    fflush(tmp);
		    fclose(tab);
		}
		if ((status = spawnlp(P_WAIT, editor, editor, work, 0))) {
		    remove(work);
		    fatal_message(status == -1 ? "unable to start %s" : "%s exited %d", editor, status);
		}
		setegid(egid);
		seteuid(euid);
	    }
	    remove(work);
	    rewind(tmp);
	}
    } else if (optind == argc - 1 && action == CREATE) {
	/* copy file onto crontab */
	if (access(argv[optind], R_OK) != 0 || (tmp = fopen(argv[optind], "r")) == 0) {
	    fatal_message("%s: %s", argv[optind], strerror(errno));
	}
    } else {
	fatal_message("too many arguments");
    }

    if(chdir(crondir) != 0)
	fatal_message("crontab %s: %s", strerror(errno), crondir);

    if (not_authorized(pwent->pw_name) && pwent->pw_uid != 0) {
	fprintf(stderr, "warning: no permission for cron: %s\n", pwent->pw_name);
    }

    if (action == LIST) {
	if ((tab = fopen(crontab, "r")) == 0) {
	    if(errno == ENOENT) 
		fatal_message("no crontab for %s", pwent->pw_name);
	    fatal_message("%s: %s", pwent->pw_name, strerror(errno));
	} else {
	    while ((ch = fgetc(tab)) != EOF)
		putchar(ch);
	    fclose(tab);
	}
    } else {
	/* drop and store euid/egid, use uid/gid */ 
	egid = getegid();
	euid = geteuid();
	setegid(getgid());
	seteuid(getuid());

	chmod(crontab, S_IRWXU);	/* -rw---- */
	if (action == REMOVE) {
	    if (remove(crontab) == -1 && errno != ENOENT) {
		fatal_message("%s: %s", strerror(errno), crontab);
	    }
	} else if (action == CREATE || action == EDIT) {
	    if ((tab = fopen(crontab, "w")) == NULL) {
		fatal_message("%s: %s", strerror(errno), crontab);
	    }

	    while ((ch = fgetc(tmp)) != EOF)
		fputc(ch, tab);

	    fflush(tab); /* Changing write permissions later! */

	    fchown(fileno(tab), pwent->pw_uid, pwent->pw_gid);
	    fchmod(fileno(tab), S_IRUSR);	/* -r----- */
	    fclose(tab);
	    fclose(tmp);

	}
	/* restore euid/egid for kill */
	setegid(egid);
	seteuid(euid);

	/* Notify server */
#ifdef __WATCOMC__
	if (server != -1 && Send(server, pwent->pw_name, 0, strlen(pwent->pw_name) + 1, 0) < 0) {
#else
	if(server && kill(*(pid_t *)server, SIGUSR1) == -1) {
#endif
		fatal_message("inform cron about update: %s", strerror(errno));
	}
    }
    return EXIT_SUCCESS;
}