41 #include <sys/utsname.h> 44 #include <glib/gi18n.h> 45 #include <glib/gstdio.h> 80 {
"RedHat",
"/etc/redhat-release" },
81 {
"RedHat",
"/etc/redhat_version" },
82 {
"Sun",
"/etc/sun-release" },
83 {
"SuSE",
"/etc/SuSE-release" },
84 {
"SuSE",
"/etc/novell-release" },
85 {
"SuSE",
"/etc/sles-release" },
86 {
"SuSE",
"/etc/os-release" },
87 {
"Debian",
"/etc/debian_version" },
88 {
"Debian",
"/etc/debian_release" },
89 {
"Ubuntu",
"/etc/lsb-release" },
90 {
"Mandrake",
"/etc/mandrake-release" },
91 {
"Mandriva",
"/etc/mandriva-release" },
92 {
"Mandrake",
"/etc/mandrakelinux-release" },
93 {
"TurboLinux",
"/etc/turbolinux-release" },
94 {
"Fedora Core",
"/etc/fedora-release" },
95 {
"Gentoo",
"/etc/gentoo-release" },
96 {
"Novell",
"/etc/nld-release" },
97 {
"Annvix",
"/etc/annvix-release" },
98 {
"Arch",
"/etc/arch-release" },
99 {
"Arklinux",
"/etc/arklinux-release" },
100 {
"Aurox",
"/etc/aurox-release" },
101 {
"BlackCat",
"/etc/blackcat-release" },
102 {
"Cobalt",
"/etc/cobalt-release" },
103 {
"Conectiva",
"/etc/conectiva-release" },
104 {
"Immunix",
"/etc/immunix-release" },
105 {
"Knoppix",
"/etc/knoppix_version" },
106 {
"Linux-From-Scratch",
"/etc/lfs-release" },
107 {
"Linux-PPC",
"/etc/linuxppc-release" },
108 {
"MkLinux",
"/etc/mklinux-release" },
109 {
"PLD",
"/etc/pld-release" },
110 {
"Slackware",
"/etc/slackware-version" },
111 {
"Slackware",
"/etc/slackware-release" },
112 {
"SMEServer",
"/etc/e-smith-release" },
113 {
"Solaris",
"/etc/release" },
114 {
"Solus",
"/etc/solus-release" },
115 {
"Tiny Sofa",
"/etc/tinysofa-release" },
116 {
"UltraPenguin",
"/etc/ultrapenguin-release" },
117 {
"UnitedLinux",
"/etc/UnitedLinux-release" },
118 {
"VALinux",
"/etc/va-release" },
119 {
"Yellow Dog",
"/etc/yellowdog-release" },
125 TRACE_CALL(__func__);
131 sub = strstr(haystack, needle);
135 return sub - haystack;
143 TRACE_CALL(__func__);
146 g_return_val_if_fail(haystack != NULL, -1);
147 if (haystack->len == 0)
150 g_return_val_if_fail(start >= 0, -1);
151 if (start >= (gint)haystack->len)
154 g_return_val_if_fail(!EMPTY(needle), -1);
175 TRACE_CALL(__func__);
176 g_string_erase(str, pos, len);
178 g_string_insert(str, pos, replace);
179 pos += strlen(replace);
195 TRACE_CALL(__func__);
198 gsize needle_length = strlen(needle);
222 gchar *p = g_malloc(strlen(s) + 1);
227 if (*s !=
'\t' && *s !=
'\n' && *s !=
'\"')
253 TRACE_CALL(__func__);
256 gchar *distro_desc = NULL;
259 if (g_stat(filename, &st) == -1) {
260 g_debug(
"%s: could not stat the file %s\n", __func__, filename);
264 g_debug(
"%s: File %s is %lu bytes long\n", __func__, filename, st.st_size);
265 if (st.st_size > 131072)
268 if (!g_file_get_contents(filename, &distro_desc, &file_sz, &err)) {
269 g_debug(
"%s: could not get the file content%s: %s\n", __func__, filename, err->message);
275 g_debug(
"%s: Cannot work with empty file.\n", __FUNCTION__);
279 g_debug(
"%s: Distro description %s\n", __func__, distro_desc);
289 gchar *lang = setlocale(LC_ALL, NULL);
292 if (!lang || lang[0] ==
'\0') {
295 ptr = strchr(lang,
'.');
308 TRACE_CALL(__func__);
318 TRACE_CALL(__func__);
328 TRACE_CALL(__func__);
338 TRACE_CALL(__func__);
339 gchar *lsb_id = NULL;
340 if (g_spawn_command_line_sync(
"/usr/bin/lsb_release -si", &lsb_id, NULL, NULL, NULL))
351 TRACE_CALL(__func__);
352 gchar *lsb_description = NULL;
355 if (g_spawn_command_line_sync(
"/usr/bin/lsb_release -sd", &lsb_description, NULL, NULL, &err)) {
356 return lsb_description;
358 g_debug(
"%s: could not execute lsb_release %s\n", __func__, err->message);
361 g_debug(
"%s: lsb_release %s\n", __func__, lsb_description);
371 TRACE_CALL(__func__);
372 gchar *lsb_release = NULL;
373 if (g_spawn_command_line_sync(
"/usr/bin/lsb_release -sr", &lsb_release, NULL, NULL, NULL))
384 TRACE_CALL(__func__);
385 gchar *lsb_codename = NULL;
386 if (g_spawn_command_line_sync(
"/usr/bin/lsb_release -sc", &lsb_codename, NULL, NULL, NULL))
398 TRACE_CALL(__func__);
399 gchar *etc_release = NULL;
403 r = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
405 for (i = 0; distroArray[i].
filename != NULL; i++) {
406 g_debug(
"%s: File %s\n", __func__, distroArray[i].filename);
409 if (etc_release[0] !=
'\0') {
410 g_debug(
"%s: Distro description %s\n", __func__, etc_release);
411 g_hash_table_insert(r, distroArray[i].filename, etc_release);
426 TRACE_CALL(__func__);
427 gchar *kernel_string;
432 kernel_string = g_strdup_printf(
"%s;%s;%s\n",
436 if (!kernel_string || kernel_string[0] ==
'\0') {
438 g_free(kernel_string);
439 kernel_string = g_strdup_printf(
"%s;%s;%s\n",
444 return kernel_string;
464 #define BLOCK_SIZE 4096 465 unsigned char block[BLOCK_SIZE];
470 file = fopen(filename,
"r");
474 sha1 = g_checksum_new(G_CHECKSUM_SHA1);
479 bytes_read = fread(block, 1, 4096, file);
480 if (bytes_read == 0) {
483 else if (ferror(file))
486 g_checksum_update(sha1, block, bytes_read);
490 digest = g_strdup(g_checksum_get_string(sha1));
494 g_checksum_free(sha1);
struct distro_info DistroInfo
gint remmina_utils_string_find(GString *haystack, gint start, gint end, const gchar *needle)
gint remmina_utils_strpos(const gchar *haystack, const gchar *needle)
gchar * remmina_utils_get_lsb_codename()
Print the Distribution codename as specified by the lsb_release command.
gchar * remmina_utils_get_lsb_id()
Print the Distributor as specified by the lsb_release command.
const gchar * remmina_utils_get_kernel_name()
Return the OS name as in "uname -s".
const gchar * remmina_utils_get_kernel_release()
Return the OS version as in "uname -r".
gchar * remmina_utils_string_strip(const gchar *s)
Strip , and " from a given string.
static gchar * remmina_utils_read_distrofile(gchar *filename)
OS related functions.
gchar * remmina_utils_get_lsb_release()
Print the Distribution release name as specified by the lsb_release command.
gchar * remmina_utils_get_lang()
Return the current language defined in the LC_ALL.
const gchar * remmina_utils_get_os_info()
A sample function to show how use the other fOS related functions.
struct lsb_distro_info LSBDistroInfo
gchar * remmina_utils_get_lsb_description()
Print the Distribution description as specified by the lsb_release command.
gchar * remmina_sha1_file(const gchar *filename)
Create a hexadecimal string version of the SHA-1 digest of the contents of the named file...
guint remmina_utils_string_replace_all(GString *haystack, const gchar *needle, const gchar *replace)
Replaces all occurrences of needle in haystack with replace.
static DistroInfo distroArray[]
GHashTable * remmina_utils_get_etc_release()
Print the distribution description if found.
gint remmina_utils_string_replace(GString *str, gint pos, gint len, const gchar *replace)
const gchar * remmina_utils_get_kernel_arch()
Return the machine hardware name as in "uname -m".