#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#define MAX_OLDPAG_GID 0xff00
#define MAXCELLNAMELEN 256
+#define MAXUSERNAMELEN 256
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int afs_initialized = 0;
char cellname[MAXCELLNAMELEN];
char homedir_prefix[MAXPATHLEN];
+char cell_root[MAXPATHLEN];
int homedir_prefix_len=0;
char homedirs_method=0;
char shells_method=0;
int res;
idlist lid;
namelist lnames;
+ char uname[MAXUSERNAMELEN];
init_afs();
lid.idlist_val = 0;
lid.idlist_len = 0;
- lnames.namelist_val = (prname*)name;
+ lnames.namelist_val = (prname*)uname;
+ // apparently ubik expects to be able to modify this?
+ strncpy(uname, name, MAXUSERNAMELEN);
lnames.namelist_len = 1;
if (ubik_Call(PR_NameToID,pruclient,0,&lnames,&lid) != PRSUCCESS) {
int init_afs() {
FILE *thiscell;
int len;
+ struct stat statbuf;
- if (afs_initialized) return 0;
-
+ if (afs_initialized) {
+ /* wait until /afs/@cell/ appears as a proxy for "the network is up" */
+ if (stat(cell_root, &statbuf)) return -1;
+ return 0;
+ }
+
if (pthread_mutex_lock(&mutex)) return -1;
do {
homedirs_method=HOMEDIR_PREFIX;
if (cellname[len-1] == '\n') len--;
cellname[len]='\0';
+
+ /* wait until /afs/@cell/ appears as a proxy for "the network is up" */
+ sprintf(cell_root,"/afs/%s/",cellname);
+ if (stat(cell_root, &statbuf)) break;
+
sprintf(homedir_prefix,"/afs/%s/user/",cellname);
homedir_prefix_len=strlen(homedir_prefix);
-
+
+ /* time out requests after 5 seconds to avoid hanging things */
+ rx_SetRxDeadTime(5);
+
if (pr_Initialize(0L,AFSDIR_CLIENT_ETC_DIRPATH, 0)) break;
afs_initialized = 1;