<commit_before>/* ISC license. */

#include <unistd.h>
#include <errno.h>
#include <signal.h>

#include <skalibs/allreadwrite.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/types.h>
#include <skalibs/tai.h>
#include <skalibs/iopause.h>
#include <skalibs/djbunix.h>
#include <skalibs/exec.h>

#include <s6/config.h>

#define USAGE "s6-setlock [ -r | -w ] [ -n | -N | -t timeout ] lockfile prog..."
#define dieusage() strerr_dieusage(100, USAGE)

int main (int argc, char const *const *argv)
{
  unsigned int nb = 0, ex = 1 ;
  unsigned int timeout = 0 ;
  PROG = "s6-setlock" ;
  for (;;)
  {
    int opt = subgetopt(argc, argv, "nNrwt:") ;
    if (opt == -1) break ;
    switch (opt)
    {
      case 'n' : nb = 1 ; break ;
      case 'N' : nb = 0 ; break ;
      case 'r' : ex = 0 ; break ;
      case 'w' : ex = 1 ; break ;
      case 't' : if (!uint0_scan(subgetopt_here.arg, &timeout)) dieusage() ; nb = 2 ; break ;
      default : dieusage() ;
    }
  }
  argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
  if (argc < 2) dieusage() ;

  if (nb < 2)
  {
    int r ;
    int fd = open_create(argv[0]) ;
    if (fd < 0) strerr_diefu2sys(111, "open_create ", argv[0]) ;
    r = fd_lock(fd, ex, nb) ;<commit_msg> bugfix: setlock -r<commit_after>/* ISC license. */

#include <unistd.h>
#include <errno.h>
#include <signal.h>

#include <skalibs/allreadwrite.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/types.h>
#include <skalibs/tai.h>
#include <skalibs/iopause.h>
#include <skalibs/djbunix.h>
#include <skalibs/exec.h>

#include <s6/config.h>

#define USAGE "s6-setlock [ -r | -w ] [ -n | -N | -t timeout ] lockfile prog..."
#define dieusage() strerr_dieusage(100, USAGE)

int main (int argc, char const *const *argv)
{
  unsigned int nb = 0, ex = 1 ;
  unsigned int timeout = 0 ;
  PROG = "s6-setlock" ;
  for (;;)
  {
    int opt = subgetopt(argc, argv, "nNrwt:") ;
    if (opt == -1) break ;
    switch (opt)
    {
      case 'n' : nb = 1 ; break ;
      case 'N' : nb = 0 ; break ;
      case 'r' : ex = 0 ; break ;
      case 'w' : ex = 1 ; break ;
      case 't' : if (!uint0_scan(subgetopt_here.arg, &timeout)) dieusage() ; nb = 2 ; break ;
      default : dieusage() ;
    }
  }
  argc -= subgetopt_here.ind ; argv += subgetopt_here.ind ;
  if (argc < 2) dieusage() ;

  if (nb < 2)
  {
    int r, fd ;
    if (ex)
    {
      fd = open_create(argv[0]) ;
      if (fd < 0) strerr_diefu3sys(111, "open ", argv[0], " for writing") ;
    }
    else
    {
      fd = open_read(argv[0]) ;
      if (fd < 0)
      {
        if (errno != ENOENT) strerr_diefu3sys(111, "open ", argv[0], " for reading") ;
        fd = open_create(argv[0]) ;
        if (fd < 0) strerr_diefu2sys(111, "create ", argv[0]) ;
        close(fd) ;
        fd = open_read(argv[0]) ;
        if (fd < 0) strerr_diefu3sys(111, "open ", argv[0], " for reading") ;
      }
    }
    r = fd_lock(fd, ex, nb) ;
{'fraction_non_alphanumeric': 0.17631133671742807, 'fraction_numerical': 0.024703891708967852, 'mean_word_length': 2.56144578313253, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7302376', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1253, 'n_words': 302}