int chat_register(const char *hostname, const char *username) { char *passwd = chat_register_rpc(hostname, username); if (strlen(passwd) == 0) { fprintf(stderr, "Register failed\n"); exit(EXIT_SUCCESS); } char *workdir = getworkdir(); char *passwdfile = pathjoin(workdir, PASSWDFILE); free(workdir); FILE *fpasswd = fopen(passwdfile, "w"); fprintf(fpasswd, "%s\n", passwd); fclose(fpasswd); chmod(passwdfile, 0600); fprintf(stderr, "%s\n", passwd); return 0; }
void main(int argc, char *argv[]) { char *srv, *mtpt; char buf[MAXPATH]; inflateinit(); fmtinstall('H', Hfmt); srv = nil; mtpt = "/mnt/hg"; ARGBEGIN { case 'D': chatty9p++; break; case 'm': mtpt = EARGF(usage()); break; case 's': srv = EARGF(usage()); break; default: usage(); } ARGEND; if(getworkdir(workdir, *argv) < 0) sysfatal("can't find workdir: %r"); snprint(buf, sizeof(buf), "%s/.hg/store/00changelog", workdir); if(revlogopen(&changelog, buf, OREAD) < 0) sysfatal("can't open changelog: %r\n"); snprint(buf, sizeof(buf), "%s/.hg/store/00manifest", workdir); if(revlogopen(&manifest, buf, OREAD) < 0) sysfatal("can't open menifest: %r\n"); postmountsrv(&fs, srv, mtpt, MREPL); exits(0); }
sqlite3 * getdb () { char *workdir = getworkdir(); char *dbfile = pathjoin(workdir, DBFILE); free(workdir); int notfound = 0; int rc; struct stat st; rc = stat(dbfile, &st); if (rc == -1) { if (errno == ENOENT) { notfound = 1; } else { fprintf(stderr, "Error stating %s: %d\n", dbfile, errno); exit(EXIT_FAILURE); } } sqlite3 *db; rc = sqlite3_open(dbfile, &db); if (rc != SQLITE_OK) { fprintf(stderr, "Can't open database %s.\n", sqlite3_errmsg(db)); sqlite3_close(db); exit(EXIT_FAILURE); } if (notfound) { fprintf(stderr, "Initializing database.\n"); initdb(db); } return db; }