~ubuntu-branches/ubuntu/utopic/cups/utopic

« back to all changes in this revision

Viewing changes to scheduler/job.c

  • Committer: Package Import Robot
  • Author(s): Didier Raboud, Till Kamppeter, Steve Langasek, Didier Raboud
  • Date: 2014-01-03 18:42:39 UTC
  • mfrom: (1.3.2)
  • mto: This revision was merged to the branch mainline in revision 142.
  • Revision ID: package-import@ubuntu.com-20140103184239-juzq32ckr7ra49b3
* New 1.7.0 upstream release

[ Till Kamppeter ]
* Refresh most patches with quilt
* Removed usb-backend-do-not-crash-if-usb-disabled-in-bios and
  cupsd-no-crash-on-avahi-threaded-poll-shutdown patches as they got
  applied upstream
* Removed drop-arch-specifics-from-doc patch as it is not needed
  anymore
* Updated drop_unnecessary_dependencies, manpage-hyphen-minus,
  manpage-translations and ppd-poll-with-client-conf patches manually
  to apply to the new CUPS version
* Added error counting exception from
  usb-backend-do-not-crash-if-usb-disabled-in-bios to
  tests-ignore-warnings
* Install the newly added ippfind utility and its manpage in
  cups-client
* Added pwg.h to libcups2-dev package
* Call dh_auto_clean only if the file Makedefs is present, to avoid a
  FTBFS
* Added color management extensions from Joe Simon's GSoC 2013
  project.
* Patch cups-files.conf to activate CUPS daemon syncing of files when
  closing, so that config files (like printers.conf) do not
  mysteriously disappear (LP: #1157972)
* In the AppArmor profile, allow execution of programs in
  /etc/cups/interfaces/, needed to make CUPS working with queues based
  on System V interface scripts, especially PPD-less queues
  auto-generated by cups-browsed from cups-filters 1.0.41 on.
* Silenced AppArmor noise from udev.conf in syslog (LP: #1229766)

[ Steve Langasek ]
* Add cups-filters (>= 1.0.42) as alternative to foomatic-filters
  (which is deprecated) in package relationships

[ Didier Raboud ]
* Remove Roger Leigh from uploaders on his request with thanks for his
  past work!
* Switch avahi LSB Should-Start dependency to be avahi-daemon; also
  bump package relationship to >= 0.6.31-3~ (Closes: #731608)
* Refresh the manpage translation files
* Move the USB backend quirk rules file to cups-server-common
* Add 38 new 1.7.0 libcups2 symbols
* Mark one C++ libcupsppdc1 symbol as optional as it isn't exported in
  1.7.0 anymore
* Import Fedora patches:
  - to avoid sign-extending CRCs in gz decompression
  - to build with full read-only relocations
  - to fix job history logging (upstream patch)
  - to set the internal default for SyncOnClose to Yes, instead of
    only configuring it to Yes
  - to fix a stringpool corruption issue
  - to prevent USB timeouts causing incorrect print output
* Import Fedora patch updates:
  - to dont-use-dbus-from-two-threads patch so it removes a call to
    avahi_threaded_poll_stop()
  - to avoid_stale_lockfile_in_dbus_notifier patch to call _exit when
    handling SIGTERM
* Move manpage-translations patch at the very end of the patch series
  to have it include all our patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * "$Id: job.c 11173 2013-07-23 12:31:34Z msweet $"
 
2
 * "$Id: job.c 11147 2013-07-17 02:54:31Z msweet $"
3
3
 *
4
4
 *   Job management routines for the CUPS scheduler.
5
5
 *
598
598
 
599
599
  memset(job->filters, 0, sizeof(job->filters));
600
600
 
601
 
 
602
601
  if (job->printer->raw)
603
602
  {
604
603
   /*
667
666
                   "FINAL_CONTENT_TYPE=%s/%s", filter->dst->super,
668
667
                   filter->dst->type);
669
668
      }
 
669
      else
 
670
        snprintf(final_content_type, sizeof(final_content_type),
 
671
                 "FINAL_CONTENT_TYPE=printer/%s", job->printer->name);
670
672
    }
671
673
 
672
674
   /*
936
938
                          IPP_TAG_LANGUAGE);
937
939
 
938
940
#ifdef __APPLE__
939
 
  strcpy(apple_language, "APPLE_LANGUAGE=");
 
941
  strlcpy(apple_language, "APPLE_LANGUAGE=", sizeof(apple_language));
940
942
  _cupsAppleLanguage(attr->values[0].string.text,
941
943
                     apple_language + 15, sizeof(apple_language) - 15);
942
944
#endif /* __APPLE__ */
949
951
        * the POSIX locale...
950
952
        */
951
953
 
952
 
        strcpy(lang, "LANG=C");
 
954
        strlcpy(lang, "LANG=C", sizeof(lang));
953
955
        break;
954
956
 
955
957
    case 2 :
1007
1009
      * All of these strcpy's are safe because we allocated the psr string...
1008
1010
      */
1009
1011
 
1010
 
      strcpy(printer_state_reasons, "PRINTER_STATE_REASONS=");
 
1012
      strlcpy(printer_state_reasons, "PRINTER_STATE_REASONS=", psrlen);
1011
1013
      for (psrptr = printer_state_reasons + 22, i = 0;
1012
1014
           i < job->printer->num_reasons;
1013
1015
           i ++)
1014
1016
      {
1015
1017
        if (i)
1016
1018
          *psrptr++ = ',';
1017
 
        strcpy(psrptr, job->printer->reasons[i]);
 
1019
        strlcpy(psrptr, job->printer->reasons[i],
 
1020
                psrlen - (psrptr - printer_state_reasons));
1018
1021
        psrptr += strlen(psrptr);
1019
1022
      }
1020
1023
    }
1126
1129
  * Now create processes for all of the filters...
1127
1130
  */
1128
1131
 
1129
 
  cupsdSetPrinterReasons(job->printer, "-cups-missing-filter-warning,"
1130
 
                                       "cups-insecure-filter-warning");
1131
 
 
1132
1132
  for (i = 0, slot = 0, filter = (mime_filter_t *)cupsArrayFirst(filters);
1133
1133
       filter;
1134
1134
       i ++, filter = (mime_filter_t *)cupsArrayNext(filters))
1887
1887
                                                 fileid);
1888
1888
        }
1889
1889
 
 
1890
        if (compressions)
 
1891
          job->compressions = compressions;
 
1892
 
 
1893
        if (filetypes)
 
1894
          job->filetypes = filetypes;
 
1895
 
1890
1896
        if (!compressions || !filetypes)
1891
1897
        {
1892
1898
          cupsdLogMessage(CUPSD_LOG_ERROR,
1896
1902
          ippDelete(job->attrs);
1897
1903
          job->attrs = NULL;
1898
1904
 
1899
 
          if (compressions)
1900
 
            free(compressions);
1901
 
 
1902
 
          if (filetypes)
1903
 
            free(filetypes);
1904
 
 
1905
1905
          if (job->compressions)
1906
1906
          {
1907
1907
            free(job->compressions);
1918
1918
          return (0);
1919
1919
        }
1920
1920
 
1921
 
        job->compressions = compressions;
1922
 
        job->filetypes    = filetypes;
1923
 
        job->num_files    = fileid;
 
1921
        job->num_files = fileid;
1924
1922
      }
1925
1923
 
1926
1924
      job->filetypes[fileid - 1] = mimeFileType(MimeDatabase, jobfile, NULL,
3063
3061
        job_state = IPP_JOB_COMPLETED;
3064
3062
        message   = "Job completed.";
3065
3063
 
3066
 
        ippSetString(job->attrs, &job->reasons, 0,
3067
 
                     "job-completed-successfully");
 
3064
        if (!job->status)
 
3065
          ippSetString(job->attrs, &job->reasons, 0,
 
3066
                       "job-completed-successfully");
3068
3067
        break;
3069
3068
 
3070
3069
    case IPP_JOB_STOPPED :
3250
3249
            * Hold the job...
3251
3250
            */
3252
3251
 
3253
 
            cupsdSetJobHoldUntil(job, "indefinite", 1);
3254
 
            ippSetString(job->attrs, &job->reasons, 0,
3255
 
                         "job-hold-until-specified");
3256
 
 
3257
 
            job_state = IPP_JOB_HELD;
3258
 
            message   = "Job held indefinitely due to backend errors; please "
 
3252
            const char *reason = ippGetString(job->reasons, 0, NULL);
 
3253
 
 
3254
            cupsdLogJob(job, CUPSD_LOG_DEBUG, "job-state-reasons=\"%s\"",
 
3255
                        reason);
 
3256
 
 
3257
            if (!reason || strncmp(reason, "account-", 8))
 
3258
            {
 
3259
              cupsdSetJobHoldUntil(job, "indefinite", 1);
 
3260
 
 
3261
              ippSetString(job->attrs, &job->reasons, 0,
 
3262
                           "job-hold-until-specified");
 
3263
              message = "Job held indefinitely due to backend errors; please "
3259
3264
                        "consult the error_log file for details.";
 
3265
            }
 
3266
            else if (!strcmp(reason, "account-info-needed"))
 
3267
            {
 
3268
              cupsdSetJobHoldUntil(job, "indefinite", 0);
 
3269
 
 
3270
              message = "Job held indefinitely - account information is "
 
3271
                        "required.";
 
3272
            }
 
3273
            else if (!strcmp(reason, "account-closed"))
 
3274
            {
 
3275
              cupsdSetJobHoldUntil(job, "indefinite", 0);
 
3276
 
 
3277
              message = "Job held indefinitely - account has been closed.";
 
3278
            }
 
3279
            else if (!strcmp(reason, "account-limit-reached"))
 
3280
            {
 
3281
              cupsdSetJobHoldUntil(job, "indefinite", 0);
 
3282
 
 
3283
              message = "Job held indefinitely - account limit has been "
 
3284
                        "reached.";
 
3285
            }
 
3286
            else
 
3287
            {
 
3288
              cupsdSetJobHoldUntil(job, "indefinite", 0);
 
3289
 
 
3290
              message = "Job held indefinitely - account authorization failed.";
 
3291
            }
 
3292
 
 
3293
            job_state = IPP_JOB_HELD;
3260
3294
          }
3261
3295
          break;
3262
3296
 
3290
3324
            job_state = IPP_JOB_HELD;
3291
3325
            message   = "Job held for authentication.";
3292
3326
 
3293
 
            ippSetString(job->attrs, &job->reasons, 0,
3294
 
                         "cups-held-for-authentication");
 
3327
            if (strncmp(job->reasons->values[0].string.text, "account-", 8))
 
3328
              ippSetString(job->attrs, &job->reasons, 0,
 
3329
                           "cups-held-for-authentication");
3295
3330
          }
3296
3331
          break;
3297
3332
 
3475
3510
                        "com.apple.print.DocumentTicket.PMSpoolFormat",
3476
3511
                        IPP_TAG_ZERO) &&
3477
3512
      !ippFindAttribute(job->attrs, "APPrinterPreset", IPP_TAG_ZERO) &&
3478
 
      (ippFindAttribute(job->attrs, "output-mode", IPP_TAG_ZERO) ||
3479
 
       ippFindAttribute(job->attrs, "print-color-mode", IPP_TAG_ZERO) ||
 
3513
      (ippFindAttribute(job->attrs, "print-color-mode", IPP_TAG_ZERO) ||
3480
3514
       ippFindAttribute(job->attrs, "print-quality", IPP_TAG_ZERO)))
3481
3515
  {
3482
3516
   /*
3483
 
    * Map output-mode and print-quality to a preset...
 
3517
    * Map print-color-mode and print-quality to a preset...
3484
3518
    */
3485
3519
 
3486
3520
    if ((attr = ippFindAttribute(job->attrs, "print-color-mode",
3487
 
                                 IPP_TAG_KEYWORD)) == NULL)
3488
 
      attr = ippFindAttribute(job->attrs, "output-mode", IPP_TAG_KEYWORD);
3489
 
 
3490
 
    if (attr && !strcmp(attr->values[0].string.text, "monochrome"))
 
3521
                                 IPP_TAG_KEYWORD)) != NULL &&
 
3522
        !strcmp(attr->values[0].string.text, "monochrome"))
3491
3523
      print_color_mode = _PWG_PRINT_COLOR_MODE_MONOCHROME;
3492
3524
    else
3493
3525
      print_color_mode = _PWG_PRINT_COLOR_MODE_COLOR;
3674
3706
          attr->value_tag == IPP_TAG_MIMETYPE ||
3675
3707
          attr->value_tag == IPP_TAG_NAMELANG ||
3676
3708
          attr->value_tag == IPP_TAG_TEXTLANG ||
3677
 
          (attr->value_tag == IPP_TAG_URI && strcmp(attr->name, "job-uuid")) ||
 
3709
          (attr->value_tag == IPP_TAG_URI && strcmp(attr->name, "job-uuid") &&
 
3710
           strcmp(attr->name, "job-authorization-uri")) ||
3678
3711
          attr->value_tag == IPP_TAG_URISCHEME ||
3679
3712
          attr->value_tag == IPP_TAG_BEGIN_COLLECTION) /* Not yet supported */
3680
3713
        continue;
3689
3722
        continue;
3690
3723
 
3691
3724
      if (!strncmp(attr->name, "job-", 4) &&
 
3725
          strcmp(attr->name, "job-account-id") &&
 
3726
          strcmp(attr->name, "job-accounting-user-id") &&
 
3727
          strcmp(attr->name, "job-authorization-uri") &&
3692
3728
          strcmp(attr->name, "job-billing") &&
3693
3729
          strcmp(attr->name, "job-impressions") &&
3694
3730
          strcmp(attr->name, "job-originating-host-name") &&
 
3731
          strcmp(attr->name, "job-password") &&
 
3732
          strcmp(attr->name, "job-password-encryption") &&
3695
3733
          strcmp(attr->name, "job-uuid") &&
3696
3734
          !(job->printer->type & CUPS_PRINTER_REMOTE))
3697
3735
        continue;
3798
3836
  for (i = num_pwgppds, pwgppd = pwgppds; i > 0; i --, pwgppd ++)
3799
3837
  {
3800
3838
    *optptr++ = ' ';
3801
 
    strcpy(optptr, pwgppd->name);
 
3839
    strlcpy(optptr, pwgppd->name, optlength - (optptr - options));
3802
3840
    optptr += strlen(optptr);
3803
3841
    *optptr++ = '=';
3804
 
    strcpy(optptr, pwgppd->value);
 
3842
    strlcpy(optptr, pwgppd->value, optlength - (optptr - options));
3805
3843
    optptr += strlen(optptr);
3806
3844
  }
3807
3845
 
4177
4215
                      line, linenum);
4178
4216
  }
4179
4217
 
 
4218
  if (job)
 
4219
  {
 
4220
    cupsdLogMessage(CUPSD_LOG_ERROR,
 
4221
                    "Missing </Job> directive on line %d.", linenum);
 
4222
    cupsdDeleteJob(job, CUPSD_JOB_PURGE);
 
4223
  }
 
4224
 
4180
4225
  cupsFileClose(fp);
4181
4226
}
4182
4227
 
4338
4383
  {
4339
4384
    snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot,
4340
4385
             job->id, i);
4341
 
    if (Classification)
4342
 
      cupsdRemoveFile(filename);
4343
 
    else
4344
 
      unlink(filename);
 
4386
    cupsdUnlinkOrRemoveFile(filename);
4345
4387
  }
4346
4388
 
4347
4389
  free(job->filetypes);
4372
4414
 
4373
4415
  snprintf(filename, sizeof(filename), "%s/c%05d", RequestRoot,
4374
4416
           job->id);
4375
 
  if (Classification)
4376
 
    cupsdRemoveFile(filename);
4377
 
  else
4378
 
    unlink(filename);
 
4417
  cupsdUnlinkOrRemoveFile(filename);
4379
4418
 
4380
4419
  LastEvent |= CUPSD_EVENT_PRINTER_STATE_CHANGED;
4381
4420
}
4435
4474
start_job(cupsd_job_t     *job,         /* I - Job ID */
4436
4475
          cupsd_printer_t *printer)     /* I - Printer to print job */
4437
4476
{
 
4477
  const char    *filename;              /* Support filename */
 
4478
 
 
4479
 
4438
4480
  cupsdLogMessage(CUPSD_LOG_DEBUG2, "start_job(job=%p(%d), printer=%p(%s))",
4439
4481
                  job, job->id, printer, printer->name);
4440
4482
 
4489
4531
    job->cancel_time = 0;
4490
4532
 
4491
4533
 /*
 
4534
  * Check for support files...
 
4535
  */
 
4536
 
 
4537
  cupsdSetPrinterReasons(job->printer, "-cups-missing-filter-warning,"
 
4538
                                       "cups-insecure-filter-warning");
 
4539
 
 
4540
  if (printer->pc)
 
4541
  {
 
4542
    for (filename = (const char *)cupsArrayFirst(printer->pc->support_files);
 
4543
         filename;
 
4544
         filename = (const char *)cupsArrayNext(printer->pc->support_files))
 
4545
    {
 
4546
      if (_cupsFileCheck(filename, _CUPS_FILE_CHECK_FILE, !RunUser,
 
4547
                         cupsdLogFCMessage, printer))
 
4548
        break;
 
4549
    }
 
4550
  }
 
4551
 
 
4552
 /*
4492
4553
  * Setup the last exit status and security profiles...
4493
4554
  */
4494
4555
 
4736
4797
        cupsdAddEvent(CUPSD_EVENT_JOB_PROGRESS, job->printer, job,
4737
4798
                      "Printed %d page(s).", job->sheets->values[0].integer);
4738
4799
    }
 
4800
    else if (loglevel == CUPSD_LOG_JOBSTATE)
 
4801
    {
 
4802
     /*
 
4803
      * Support "keyword" to set job-state-reasons to the specified keyword.
 
4804
      * This is sufficient for the current paid printing stuff.
 
4805
      */
 
4806
 
 
4807
      cupsdLogJob(job, CUPSD_LOG_DEBUG, "JOBSTATE: %s", message);
 
4808
 
 
4809
      ippSetString(job->attrs, &job->reasons, 0, message);
 
4810
    }
4739
4811
    else if (loglevel == CUPSD_LOG_STATE)
4740
4812
    {
4741
4813
      cupsdLogJob(job, CUPSD_LOG_DEBUG, "STATE: %s", message);
4776
4848
      cups_option_t     *attrs;         /* Attributes */
4777
4849
      const char        *attr;          /* Attribute */
4778
4850
 
4779
 
 
4780
4851
      cupsdLogJob(job, CUPSD_LOG_DEBUG, "ATTR: %s", message);
4781
4852
 
4782
4853
      num_attrs = cupsParseOptions(message, 0, &attrs);
4783
4854
 
 
4855
      if ((attr = cupsGetOption("auth-info-default", num_attrs,
 
4856
                                attrs)) != NULL)
 
4857
      {
 
4858
        job->printer->num_options = cupsAddOption("auth-info", attr,
 
4859
                                                  job->printer->num_options,
 
4860
                                                  &(job->printer->options));
 
4861
        cupsdSetPrinterAttrs(job->printer);
 
4862
 
 
4863
        cupsdMarkDirty(CUPSD_DIRTY_PRINTERS);
 
4864
      }
 
4865
 
4784
4866
      if ((attr = cupsGetOption("auth-info-required", num_attrs,
4785
4867
                                attrs)) != NULL)
4786
4868
      {
5116
5198
 
5117
5199
 
5118
5200
/*
5119
 
 * End of "$Id: job.c 11173 2013-07-23 12:31:34Z msweet $".
 
5201
 * End of "$Id: job.c 11147 2013-07-17 02:54:31Z msweet $".
5120
5202
 */