ibus: fall back from unreadable machine id
This commit is contained in:
41
ibus.c
41
ibus.c
@@ -55,24 +55,37 @@ unlinkaddr(void)
|
||||
addrowned = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
machineidfiles(char *buf, int sz, char **path, int npath)
|
||||
{
|
||||
int fd, i, n;
|
||||
|
||||
for(i = 0; i < npath; i++){
|
||||
fd = open(path[i], 0);
|
||||
if(fd < 0)
|
||||
continue;
|
||||
n = read(fd, buf, sz - 1);
|
||||
close(fd);
|
||||
if(n <= 0)
|
||||
continue;
|
||||
buf[n] = '\0';
|
||||
while(n > 0 && (buf[n-1] == '\n' || buf[n-1] == '\r'))
|
||||
buf[--n] = '\0';
|
||||
if(n > 0)
|
||||
return;
|
||||
}
|
||||
buf[0] = '\0';
|
||||
}
|
||||
|
||||
static void
|
||||
machineid(char *buf, int sz)
|
||||
{
|
||||
int fd, n;
|
||||
char *path[] = {
|
||||
"/etc/machine-id",
|
||||
"/var/lib/dbus/machine-id",
|
||||
};
|
||||
|
||||
fd = open("/etc/machine-id", 0);
|
||||
if(fd < 0)
|
||||
fd = open("/var/lib/dbus/machine-id", 0);
|
||||
if(fd < 0){
|
||||
buf[0] = '\0';
|
||||
return;
|
||||
}
|
||||
n = read(fd, buf, sz - 1);
|
||||
close(fd);
|
||||
if(n < 0) n = 0;
|
||||
buf[n] = '\0';
|
||||
while(n > 0 && (buf[n-1] == '\n' || buf[n-1] == '\r'))
|
||||
buf[--n] = '\0';
|
||||
machineidfiles(buf, sz, path, nelem(path));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user