TNG 0.7 - can't join domain

Peter Samuelson peter at cadcamlab.org
Wed Mar 1 11:14:02 GMT 2000


[Patrick J. LoPresti]
>   #define AS_ROOT  for (int _i = 1 ; become_root(_i) ; _i = 0)
> The only problem with this macro is that it uses a C++-ism.

Right.  C++ is evil!  (:

>   #define BECOME_ROOT  { become_root();
>   #define UNBECOME_ROOT  unbecome_root(); }
> 
> This is no easier to use than the current scheme, but it will give a
> compile-time error (unbalanced curlies) if you screw up.

Unfortunately if you have multiple exits from an as-root function, you
will either need to mix and match your BECOME_* and become_* calls, or
have the UNBECOME_ROOT after a goto label.  Neither is very pretty.

How about runtime checking:

  extern int as_root;
  [...]

  int as_root = 1;
  int become_root()
  {
    if(as_root)
      log("become_root(): already root\n");
    [...]
  }
  int unbecome_root()
  {
    if(as_root)
      log("unbecome_root(): already non-root\n");
    [...]
  }
  int any_function_that_never_needs_to_be_root()
  {
    if(as_root)
      log("any_function: you forgot to unbecome_root()\n");
    [...]
  }

Peter


More information about the samba-technical mailing list