-
Notifications
You must be signed in to change notification settings - Fork 0
/
setlocale.c
84 lines (73 loc) · 2.38 KB
/
setlocale.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
int main (int argc, char** argv)
{
FILE* newlocalefile = NULL;
char* language = NULL;
char* region = NULL;
char* contents = NULL;
size_t contents_len = 0;
int exitcode;
int am_root;
int unused;
if (argc != 3) {
fprintf(stderr, "Usage: %s <language> <region>\n", argv[0]);
exit(1);
}
am_root = !getpid();
language = argv[1];
region = argv[2];
newlocalefile = fopen("/var/tmp/.locale.new", "w");
if (!newlocalefile) {
exit(3);
}
contents = g_strconcat(
"#!/bin/sh\n\nunset LC_ALL\n",
"export LANG=", language, "\n",
"export LC_TIME=", language, "\n",
"export LC_MESSAGES=", language, "\n",
"export LC_NUMERIC=", region, "\n",
"export LC_MONETARY=", region, "\n",
"export LC_PAPER=", region, "\n",
"export LC_NAME=", region, "\n",
"export LC_ADDRESS=", region, "\n",
"export LC_TELEPHONE=", region, "\n",
"export LC_MEASUREMENT=", region, "\n",
"export LC_IDENTIFICATION=", region, "\n",
NULL);
contents_len = strlen(contents);
if (fwrite(contents, sizeof(char), contents_len, newlocalefile) != contents_len) {
fclose(newlocalefile);
g_free(contents);
exit(2);
}
fflush(newlocalefile);
fsync(fileno(newlocalefile));
fclose(newlocalefile);
g_free(contents);
if (am_root) {
exitcode = system("/bin/mv -f /var/tmp/.locale.new /etc/osso-af-init/locale");
if (exitcode != 0) {
g_warning("Moving '%s' to '%s' failed", "/var/tmp/.locale.new", "/etc/osso-af-init/locale");
exitcode = 3;
}
} else {
exitcode = system("sudo /bin/mv -f /var/tmp/.locale.new /etc/osso-af-init/locale");
if (exitcode != 0) {
g_warning("Moving '%s' to '%s' failed", "/var/tmp/.locale.new", "/etc/osso-af-init/locale");
exitcode = 3;
}
}
if (am_root) {
unused = system("bin/chmod 0755 /etc/osso-af-init/locale");
unused = system("bin/chown 0.0 /etc/osso-af-init/locale");
} else {
unused = system("sudo /bin/chmod 0755 /etc/osso-af-init/locale");
unused = system("sudo /bin/chown 0.0 /etc/osso-af-init/locale");
}
(void)unused;
return exitcode;
}