~ubuntu-branches/ubuntu/oneiric/vlock/oneiric

« back to all changes in this revision

Viewing changes to src/plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt
  • Date: 2008-06-17 17:13:25 UTC
  • mfrom: (1.1.2 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080617171325-ic8yy6tol0165i96
Tags: 2.2.2-3
* Don't try to chgrp to "vlock" during build time (Closes: #486665)
* Bump standards version (No changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* plugin.c -- generic plugin routines for vlock,
 
2
 *             the VT locking program for linux
 
3
 *
 
4
 * This program is copyright (C) 2007 Frank Benkstein, and is free
 
5
 * software which is freely distributable under the terms of the
 
6
 * GNU General Public License version 2, included as the file COPYING in this
 
7
 * distribution.  It is NOT public domain software, and any
 
8
 * redistribution not permitted by the GNU General Public License is
 
9
 * expressly forbidden without prior written permission from
 
10
 * the author.
 
11
 *
 
12
 */
 
13
 
 
14
#include <stdlib.h>
 
15
#include <string.h>
 
16
#include <errno.h>
 
17
 
 
18
#include "list.h"
 
19
 
 
20
#include "plugin.h"
 
21
#include "util.h"
 
22
 
 
23
/* Allocate a new plugin struct. */
 
24
struct plugin *new_plugin(const char *name, struct plugin_type *type)
 
25
{
 
26
  struct plugin *p = malloc(sizeof *p);
 
27
  char *last_slash;
 
28
 
 
29
  if (p == NULL)
 
30
    return NULL;
 
31
 
 
32
  /* For security plugin names must not contain a slash. */
 
33
  last_slash = strrchr(name, '/');
 
34
 
 
35
  if (last_slash != NULL)
 
36
    name = last_slash+1;
 
37
 
 
38
  p->name = strdup(name);
 
39
 
 
40
  if (p->name == NULL) {
 
41
    free(p);
 
42
    return NULL;
 
43
  }
 
44
 
 
45
  p->context = NULL;
 
46
  p->save_disabled = false;
 
47
 
 
48
  for (size_t i = 0; i < nr_dependencies; i++)
 
49
    p->dependencies[i] = list_new();
 
50
 
 
51
  p->type = type;
 
52
 
 
53
  if (p->type->init(p)) {
 
54
    return p;
 
55
  } else {
 
56
    destroy_plugin(p);
 
57
    return NULL;
 
58
  }
 
59
}
 
60
 
 
61
/* Destroy the given plugin. */
 
62
void destroy_plugin(struct plugin *p)
 
63
{
 
64
  /* Call destroy method. */
 
65
  p->type->destroy(p);
 
66
 
 
67
  /* Destroy dependency lists. */
 
68
  for (size_t i = 0; i < nr_dependencies; i++) {
 
69
    list_delete_for_each(p->dependencies[i], dependency_item)
 
70
      free(dependency_item->data);
 
71
 
 
72
    list_free(p->dependencies[i]);
 
73
  }
 
74
 
 
75
  free(p->name);
 
76
  free(p);
 
77
}
 
78
 
 
79
bool call_hook(struct plugin *p, const char *hook_name)
 
80
{
 
81
  return p->type->call_hook(p, hook_name);
 
82
}