]> git.ozlabs.org Git - petitboot/blob - ui/common/ui-system.c
ui/ncurses: Add support for 'add-url' action
[petitboot] / ui / common / ui-system.c
1 /*
2  *  Copyright (C) 2009 Sony Computer Entertainment Inc.
3  *  Copyright 2009 Sony Corp.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; version 2 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #if defined(HAVE_CONFIG_H)
20 #include "config.h"
21 #endif
22
23 #include <assert.h>
24 #include <errno.h>
25 #include <signal.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #include <sys/wait.h>
30
31 #include "log/log.h"
32 #include <system/system.h>
33 #include <process/process.h>
34 #include "talloc/talloc.h"
35 #include "ui-system.h"
36
37 /**
38  * pb_start_daemon - start the pb-discover daemon.
39  */
40
41 int pb_start_daemon(void *ctx)
42 {
43         struct process *process;
44         const char **argv;
45         int result;
46         char *name;
47
48         process = process_create(ctx);
49
50         argv = talloc_array(process, const char *, 2);
51         name = talloc_asprintf(process, "%s/sbin/pb-discover",
52                         pb_system_apps.prefix);
53
54         argv[0] = name;
55         argv[1] = NULL;
56
57         process->path = name;
58         process->argv = argv;
59
60         result = process_run_async(process);
61         process_release(process);
62
63         return result;
64 }
65
66 /**
67  * pb_elf_hash - Standard elf hash routine.
68  */
69
70 unsigned int pb_elf_hash(const char *str)
71 {
72         unsigned int h = 0, g;
73
74         while (*str) {
75                 h = (h << 4) + *str++;
76                 g = h & 0xf0000000;
77                 if (g)
78                         h ^= g >> 24;
79                 h &= ~g;
80         }
81         pb_log("%s: %x\n", __func__, h);
82         return h;
83 }
84
85 /**
86  * pb_cat_hash - Hashes concatenation of two strings.
87  */
88
89 unsigned int pb_cat_hash(const char *a, const char *b)
90 {
91         unsigned int h;
92         char *s;
93
94         s = talloc_asprintf(NULL, "%s%s", a, b);
95         h = pb_elf_hash(s);
96         talloc_free(s);
97
98         return h;
99 }