Code Review
/
src
/
drm-lease-manager.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Add configuration file loading and parsing
[src/drm-lease-manager.git]
/
drm-lease-manager
/
main.c
diff --git
a/drm-lease-manager/main.c
b/drm-lease-manager/main.c
index
491c80c
..
ff69e75
100644
(file)
--- a/
drm-lease-manager/main.c
+++ b/
drm-lease-manager/main.c
@@
-13,6
+13,7
@@
* limitations under the License.
*/
* limitations under the License.
*/
+#include "lease-config.h"
#include "lease-manager.h"
#include "lease-server.h"
#include "log.h"
#include "lease-manager.h"
#include "lease-server.h"
#include "log.h"
@@
-27,22
+28,32
@@
static void usage(const char *progname)
printf("Usage: %s [OPTIONS] [<DRM device>]\n\n"
"Options:\n"
"-h, --help \tPrint this help\n"
printf("Usage: %s [OPTIONS] [<DRM device>]\n\n"
"Options:\n"
"-h, --help \tPrint this help\n"
- "-v, --verbose \tEnable verbose debug messages\n",
+ "-c, --config \t path to configuration file (default "
+ "/etc/drm-lease-manager.toml)\n"
+ "-v, --verbose \tEnable verbose debug messages\n"
+ "-t, --lease-transfer \tAllow lease transfter to new clients\n"
+ "-k, --keep-on-crash \tDon't close lease on client crash\n",
progname);
}
progname);
}
-const char *opts = "v
h
";
+const char *opts = "v
tkhc:
";
const struct option options[] = {
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
const struct option options[] = {
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
+ {"lease-transfer", no_argument, NULL, 't'},
+ {"keep-on-crash", no_argument, NULL, 'k'},
+ {"config", required_argument, NULL, 'c'},
{NULL, 0, NULL, 0},
};
int main(int argc, char **argv)
{
char *device = "/dev/dri/card0";
{NULL, 0, NULL, 0},
};
int main(int argc, char **argv)
{
char *device = "/dev/dri/card0";
+ char *config_file = "/etc/drm-lease-manager.toml";
bool debug_log = false;
bool debug_log = false;
+ bool can_transfer_leases = false;
+ bool keep_on_crash = false;
int c;
while ((c = getopt_long(argc, argv, opts, options, NULL)) != -1) {
int c;
while ((c = getopt_long(argc, argv, opts, options, NULL)) != -1) {
@@
-51,6
+62,15
@@
int main(int argc, char **argv)
case 'v':
debug_log = true;
break;
case 'v':
debug_log = true;
break;
+ case 't':
+ can_transfer_leases = true;
+ break;
+ case 'k':
+ keep_on_crash = true;
+ break;
+ case 'c':
+ config_file = optarg;
+ break;
case 'h':
ret = EXIT_SUCCESS;
/* fall through */
case 'h':
ret = EXIT_SUCCESS;
/* fall through */
@@
-65,7
+85,12
@@
int main(int argc, char **argv)
dlm_log_enable_debug(debug_log);
dlm_log_enable_debug(debug_log);
- struct lm *lm = lm_create(device);
+ struct lease_config *lease_configs = NULL;
+ int num_configs = parse_config(config_file, &lease_configs);
+
+ struct lm *lm =
+ lm_create_with_config(device, num_configs, lease_configs);
+
if (!lm) {
ERROR_LOG("DRM Lease initialization failed\n");
return EXIT_FAILURE;
if (!lm) {
ERROR_LOG("DRM Lease initialization failed\n");
return EXIT_FAILURE;
@@
-87,6
+112,10
@@
int main(int argc, char **argv)
switch (req.type) {
case LS_REQ_GET_LEASE: {
int fd = lm_lease_grant(lm, req.lease_handle);
switch (req.type) {
case LS_REQ_GET_LEASE: {
int fd = lm_lease_grant(lm, req.lease_handle);
+
+ if (fd < 0 && can_transfer_leases)
+ fd = lm_lease_transfer(lm, req.lease_handle);
+
if (fd < 0) {
ERROR_LOG(
"Can't fulfill lease request: lease=%s\n",
if (fd < 0) {
ERROR_LOG(
"Can't fulfill lease request: lease=%s\n",
@@
-95,6
+124,13
@@
int main(int argc, char **argv)
break;
}
break;
}
+ struct ls_client *active_client =
+ req.lease_handle->user_data;
+ if (active_client)
+ ls_disconnect_client(ls, active_client);
+
+ req.lease_handle->user_data = req.client;
+
if (!ls_send_fd(ls, req.client, fd)) {
ERROR_LOG(
"Client communication error: lease=%s\n",
if (!ls_send_fd(ls, req.client, fd)) {
ERROR_LOG(
"Client communication error: lease=%s\n",
@@
-105,8
+141,14
@@
int main(int argc, char **argv)
break;
}
case LS_REQ_RELEASE_LEASE:
break;
}
case LS_REQ_RELEASE_LEASE:
+ case LS_REQ_CLIENT_DISCONNECT:
ls_disconnect_client(ls, req.client);
ls_disconnect_client(ls, req.client);
+ req.lease_handle->user_data = NULL;
lm_lease_revoke(lm, req.lease_handle);
lm_lease_revoke(lm, req.lease_handle);
+
+ if (!keep_on_crash || req.type == LS_REQ_RELEASE_LEASE)
+ lm_lease_close(req.lease_handle);
+
break;
default:
ERROR_LOG("Internal error: Invalid lease request\n");
break;
default:
ERROR_LOG("Internal error: Invalid lease request\n");
@@
-116,5
+158,6
@@
int main(int argc, char **argv)
done:
ls_destroy(ls);
lm_destroy(lm);
done:
ls_destroy(ls);
lm_destroy(lm);
+ release_config(num_configs, lease_configs);
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}