2 Copyright (c) 2012, Broadcom Europe Ltd
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * Daemon serving files to VideoCore from the host filing system.
46 #include <android/log.h>
50 #include "interface/vchi/vchi.h"
51 #include "interface/vcos/vcos.h"
52 #include "interface/vmcs_host/vc_vchi_filesys.h"
54 #include "vcfiled_check.h"
56 static int log_stderr; /** Debug output to stderr? */
57 static int foreground; /** Don't fork - run in foreground? */
58 static const char *work_dir = "/"; /** Working directory */
59 static const char *lock_prefix = ""; /** Lock file prefix */
60 static int lock_prefix_set = 0;
61 static const char *progname;
63 VCHI_INSTANCE_T global_initialise_instance;
64 VCHI_CONNECTION_T *global_connection;
66 void vc_host_get_vchi_state(VCHI_INSTANCE_T *initialise_instance, VCHI_CONNECTION_T **connection)
68 *initialise_instance = global_initialise_instance;
69 *connection = global_connection;
72 static void logmsg(int level, const char *fmt, ...)
79 vfprintf(stderr, fmt, ap);
84 __android_log_vprint(level, "vcfiled", fmt, ap);
86 vsyslog(level | LOG_DAEMON, fmt, ap);
92 static void usage(const char *progname)
95 fprintf(stderr,"usage: %s [-debug] [-foreground] [-root dir] [-lock prefix]\n",
97 fprintf(stderr," --debug - debug to stderr rather than syslog\n");
98 fprintf(stderr," --foreground - do not fork, stay in foreground\n");
99 fprintf(stderr," --root dir - chdir to this directory first\n");
100 fprintf(stderr," --lock prefix - prefix to append to VCFILED_LOCKFILE\n");
103 enum { OPT_DEBUG, OPT_FG, OPT_ROOT, OPT_LOCK };
105 static void parse_args(int argc, char *const *argv)
108 static struct option long_options[] =
110 {"debug", no_argument, &log_stderr, 1},
111 {"foreground", no_argument, &foreground, 1},
112 {"root", required_argument, NULL, OPT_ROOT},
113 {"lock", required_argument, NULL, OPT_LOCK},
118 int option_index = 0;
119 int c = getopt_long_only(argc, argv, "", long_options, &option_index);
124 // debug or foreground options, just sets flags directly
128 // sanity check directory
129 if (chdir(work_dir) < 0)
131 fprintf(stderr,"cannot chdir to %s: %s\n", work_dir, strerror(errno));
136 lock_prefix = optarg;
154 int main(int argc, char *const *argv)
156 VCHIQ_INSTANCE_T vchiq_instance;
161 const char *sep = strrchr(progname, '/');
165 parse_args(argc, argv);
169 if ( daemon( 0, 1 ) != 0 )
171 fprintf( stderr, "Failed to daemonize: errno = %d", errno );
176 if ( lock_prefix_set )
178 vcos_safe_sprintf( lockfile, sizeof(lockfile), 0, "%s/%s", lock_prefix, VCFILED_LOCKFILE );
182 vcos_safe_sprintf( lockfile, sizeof(lockfile), 0, "%s", VCFILED_LOCKFILE );
184 success = vcfiled_lock(lockfile, logmsg);
190 logmsg( LOG_INFO, "vcfiled started" );
194 if (vchiq_initialise(&vchiq_instance) != VCHIQ_SUCCESS)
196 logmsg(LOG_ERR, "%s: failed to open vchiq instance\n", argv[0]);
200 success = vchi_initialise( &global_initialise_instance);
201 vcos_assert(success == 0);
202 vchiq_instance = (VCHIQ_INSTANCE_T)global_initialise_instance;
204 global_connection = vchi_create_connection(single_get_func_table(),
205 vchi_mphi_message_driver_func_table());
207 vchi_connect(&global_connection, 1, global_initialise_instance);
209 vc_vchi_filesys_init (global_initialise_instance, &global_connection, 1);