EosMetricsInfo * eos_metrics_info_new (const gchar *booted_ref) { g_autoptr(GHashTable) hw_descriptors = NULL; g_autoptr(EosMetricsInfo) info = NULL; hw_descriptors = get_hw_descriptors (); info = g_object_new (EOS_TYPE_METRICS_INFO, NULL); info->vendor = cleanstr (g_strdup (g_hash_table_lookup (hw_descriptors, VENDOR_KEY))); info->product = cleanstr (g_strdup (g_hash_table_lookup (hw_descriptors, PRODUCT_KEY))); info->ref = g_strdup (booted_ref); return g_steal_pointer (&info); }
char *cleanpath(char *path) { if (path == NULL || strlen(path) == 0) return path; if (STREQ(path, "/")) return path; return cleanstr(path, SEP); }
static int chat_send(char const *str) { int r = 0; if (chat_debug & CHATDEBUG_SEND) syslog(LOG_DEBUG, "chat_send '%s'", cleanstr(str, strlen(str))); if (*str) { alarm(chat_alarm); alarmed = 0; while (r == 0 && *str) { unsigned char ch = (unsigned char)*str++; if (alarmed) r = 3; else if (ch == PAUSE_CH) usleep(500000); /* 1/2 second */ else { usleep(10000); /* be kind to modem */ if (write(STDOUT_FILENO, &ch, 1) != 1) r = alarmed ? 3 : 2; } } alarm(0); chat_unalarm(); alarmed = 0; } if (chat_debug & CHATDEBUG_SEND) syslog(LOG_DEBUG, "chat_send %s", result(r)); return r; }
char *setnbr(int nbr) { char *numb; int i; int p; p = 8; if ((numb = bunny_malloc(sizeof(char) * 10)) == NULL) return (NULL); set_line_null(numb, 10); i = 0; while (p >= 0) numb[p--] = ((nbr / (int)(pow(10, i++)) % 10) + '0'); return (cleanstr(numb)); }
char *setnbr(int nbr) { char *numb; int i; int p; p = 10; if ((numb = malloc(sizeof(char) * 10)) == NULL) return (NULL); numb[9] = 0; i = 0; while (p >= 0) numb[p--] = ((nbr / (int)(my_pow(10, i++)) % 10) + '0'); return (cleanstr(numb)); }
static int main_loop(void) { char *line = NULL; size_t len = 0; int ret = 0; /* assume success */ while (1) { const char *buf; #if defined(WITH_READLINE) if (isatty(fileno(stdin))) { line = readline("augtool> "); } else #endif if (getline(&line, &len, stdin) == -1) break; cleanstr(line, '\n'); if (line == NULL) { fprintf(stdout, "\n"); break; } if (line[0] == '#') continue; buf = NULL; switch (rpmaugRun(NULL, line, &buf)) { case RPMRC_OK: #if defined(WITH_READLINE) if (isatty(fileno(stdin))) add_history(line); #endif break; case RPMRC_NOTFOUND: goto exit; /*@notreached@*/ break; default: break; } if (buf && *buf) fprintf(stdout, "%s", buf); } exit: line = _free(line); return ret; }
static int chat_expect(const char *str) { int len, r = 0; if (chat_debug & CHATDEBUG_EXPECT) syslog(LOG_DEBUG, "chat_expect '%s'", cleanstr(str, strlen(str))); if ((len = strlen(str)) > 0) { int i = 0; char * got; if ((got = malloc(len + 1)) == NULL) r = 1; else { memset(got, 0, len+1); alarm(chat_alarm); alarmed = 0; while (r == 0 && i < len) { if (alarmed) r = 3; else { unsigned char ch; if (read(STDIN_FILENO, &ch, 1) == 1) { if (chat_debug & CHATDEBUG_RECEIVE) syslog(LOG_DEBUG, "chat_recv '%s' m=%d", cleanchr(NULL, ch), i); if (ch == str[i]) got[i++] = ch; else if (i > 0) { int j = 1; /* See if we can resync on a * partial match in our buffer */ while (j < i && memcmp(got + j, str, i - j) != 0) j++; if (j < i) memcpy(got, got + j, i - j); i -= j; } } else r = alarmed ? 3 : 2; } } alarm(0); chat_unalarm(); alarmed = 0; free(got); } } if (chat_debug & CHATDEBUG_EXPECT) syslog(LOG_DEBUG, "chat_expect %s", result(r)); return r; }